--- /dev/null
+.ExternalData
+=============
+
+The VTK ``.ExternalData`` directory is an object store for the
+CMake ExternalData module that VTK uses to manage test input
+and baseline data.
--- /dev/null
+set(XDMF_NO_REALPATH 1)
+
+# FIXME: xdmf3 only exports symbols properly on Windows.
+unset(CMAKE_CXX_VISIBILITY_PRESET)
+unset(CMAKE_VISIBILITY_INLINES_HIDDEN)
+
+vtk_module_third_party_internal(
+ LICENSE_FILES
+ "vtkxdmf3/Copyright.txt"
+ SPDX_LICENSE_IDENTIFIER
+ "BSD-4-Clause"
+ SPDX_COPYRIGHT_TEXT
+ "Copyright (c) 2011 U.S. Army Research Laboratory"
+ SPDX_DOWNLOAD_LOCATION
+ "git+https://gitlab.kitware.com/third-party/xdmf.git@for/vtk-20210822-master-gfe7dd1ca"
+ VERSION
+ "1.2.11"
+ STANDARD_INCLUDE_DIRS)
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/vtk_xdmf3.h.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/vtk_xdmf3.h")
+
+vtk_module_install_headers(
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/vtk_xdmf3.h")
--- /dev/null
+add_subdirectory(Cxx)
--- /dev/null
+vtk_add_test_cxx(vtkxdmf3CxxTests tests
+ NO_DATA NO_VALID NO_OUTPUT
+ TestIncludeXDMF3.cxx)
+vtk_test_cxx_executable(vtkxdmf3CxxTests tests)
--- /dev/null
+#include "vtk_xdmf3.h"
+// clang-format off
+#include VTKXDMF3_HEADER(core/XdmfArray.hpp)
+// clang-format on
+
+#include <cstdlib>
+
+int TestIncludeXDMF3(int /*argc*/, char* /*argv*/[])
+{
+ return EXIT_SUCCESS;
+}
--- /dev/null
+#!/usr/bin/env bash
+
+set -e
+set -x
+shopt -s dotglob
+
+readonly name="xdmf3"
+readonly ownership="XDMF Upstream <kwrobot@kitware.com>"
+readonly subtree="ThirdParty/$name/vtk$name"
+readonly repo="https://gitlab.kitware.com/third-party/xdmf.git"
+readonly tag="for/vtk-20231212-master-gfe7dd1ca"
+readonly paths="
+.gitattributes
+CMake/XdmfFunctions.cmake
+CMake/VersionSuite
+CMakeLists.txt
+Copyright.txt
+*.hpp
+*.cpp
+XdmfConfig.hpp.in
+core/CMakeLists.txt
+core/*.cpp
+core/*.hpp
+core/*.tpp
+core/XdmfConfig.hpp.in
+core/XdmfCoreConfig.hpp.in
+core/loki/
+"
+
+extract_source () {
+ git_archive
+}
+
+. "${BASH_SOURCE%/*}/../update-common.sh"
--- /dev/null
+NAME
+ VTK::xdmf3
+LIBRARY_NAME
+ vtkxdmf3
+# These are public dependencies of XdmfCore, but are exposed via a public link
+# to it, not from Xdmf3 itself.
+PRIVATE_DEPENDS
+ VTK::hdf5
+ VTK::libxml2
+TEST_DEPENDS
+ VTK::TestingCore
+THIRD_PARTY
--- /dev/null
+// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
+// SPDX-License-Identifier: BSD-3-Clause
+#ifndef vtk_xdmf3_h
+#define vtk_xdmf3_h
+
+/* Use the xdmf3 library configured for VTK. */
+#cmakedefine01 VTK_MODULE_USE_EXTERNAL_vtkxdmf3
+
+#ifdef VTK_USE_SYSTEM_XDMF3
+#else
+#define VTKXDMF3_HEADER(x) <vtkxdmf3/x>
+#endif
+
+#endif
--- /dev/null
+#ifndef PROJECT_VERSION_HPP
+#define PROJECT_VERSION_HPP
+
+/* Version Suite Class
+ * Author: Brian Panneton
+ */
+#include <string>
+#include <sstream>
+
+/**
+ * @brief Version Suite to assist in adding versioning to your project
+ *
+ * A simple way to have the library contain its own version.
+ */
+class ProjectVersion {
+ public:
+ /**
+ * Create a Version class object
+ *
+ * @param name of the project
+ */
+ ProjectVersion(std::string iProjectName, int iMajor, int iMinor, int iPatch) {
+ setProjectName(iProjectName);
+ setMajor(iMajor);
+ setMinor(iMinor);
+ setPatch(iPatch);
+ }
+
+ ProjectVersion(std::string iProjectName,
+ std::string iMajor, std::string iMinor, std::string iPatch) {
+ setProjectName(iProjectName);
+ setMajorStr(iMajor);
+ setMinorStr(iMinor);
+ setPatchStr(iPatch);
+ }
+
+ /**
+ * Get the version string
+ *
+ * @return the Version in "ProjectName Major.Minor.Patch" string format
+ */
+ std::string getFull() {
+ return getProjectName()+std::string(" ")+
+ getMajorStr()+std::string(".")+
+ getMinorStr()+std::string(".")+
+ getPatchStr();
+ }
+
+ /**
+ * Get the shorter version string
+ *
+ * @return the Version in "Major.Minor" string format
+ */
+ std::string getShort() {
+ return getMajorStr()+std::string(".")+
+ getMinorStr();
+ }
+
+ /**
+ * Get the version objects project name
+ *
+ * @return the project name in string format
+ */
+ std::string getProjectName() { return ProjectName; }
+
+ /**
+ * Get the Version Major
+ *
+ * @return the Version Major in string format
+ */
+ std::string getMajorStr()
+ {
+ if(Major != -1) return IntToStr(Major);
+ return("X");
+ }
+
+ /**
+ * Get the Version Minor
+ *
+ * @return the Version Minor in string format
+ */
+ std::string getMinorStr()
+ {
+ if(Minor != -1) return IntToStr(Minor);
+ return("X");
+ }
+
+ /**
+ * Get the Version Patch
+ *
+ * @return the Version Patch in string format
+ */
+ std::string getPatchStr()
+ {
+ if(Patch != -1) return IntToStr(Patch);
+ return("X");
+ }
+
+ /**
+ * Get the Version Major
+ *
+ * @return the Version Major in int format
+ */
+ int getMajor() { return Major; }
+
+ /**
+ * Get the Version Minor
+ *
+ * @return the Version Minor in int format
+ */
+ int getMinor() { return Minor; }
+
+ /**
+ * Get the Version Patch
+ *
+ * @return the Version Patch in int format
+ */
+ int getPatch() { return Patch; }
+
+private:
+ std::string ProjectName;
+ int Major, Minor, Patch;
+
+ std::string IntToStr(int number) {
+ std::stringstream s;
+ s << number;
+ return s.str();
+ }
+ int StrToInt(std::string string) {
+ int i = 0;
+ std::stringstream s(string);
+ if(!(s >> i)) return -1;
+ return i;
+ }
+ void setProjectName(std::string iProjectName)
+ { ProjectName = iProjectName; }
+
+ void setMajor(int iMajor) { Major = iMajor; }
+ void setMajorStr(std::string iMajor) {
+ Major = StrToInt(iMajor);
+ }
+ void setMinor(int iMinor) { Minor = iMinor; }
+ void setMinorStr(std::string iMinor) {
+ Minor = StrToInt(iMinor);
+ }
+ void setPatch(int iPatch) { Patch = iPatch; }
+ void setPatchStr(std::string iPatch) {
+ Patch = StrToInt(iPatch);
+ }
+};
+
+#endif //PROJECT_VERSION_HPP
--- /dev/null
+# Version Suite
+# Author: Brian Panneton
+# Descrition: This small suite allows you to add support
+# for versioning in your projects
+
+# This allows you to turn on and off the auto
+# update of the (project name)Version.hpp file
+if (FALSE) # XXX(kitware): force settings
+SET(VERSION_CONTROL_AUTOUPDATE OFF CACHE BOOL "Automaticaly Update The Version")
+MARK_AS_ADVANCED(VERSION_CONTROL_AUTOUPDATE)
+else ()
+set(VERSION_CONTROL_AUTOUPDATE OFF)
+endif ()
+
+# We need to make sure we have the header file
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/CMake/VersionSuite)
+
+# Default incase CalculateVerison is not called
+SET(vMajor "0")
+SET(vMinor "0")
+SET(vPatch "0")
+
+# This Macro allows you to set up the Version in a one liner
+MACRO(VersionCreate versionName versionMajor versionMinor versionPatch export_name)
+ VersionMajorSet(${versionMajor})
+ VersionMinorSet(${versionMinor})
+ VersionPatchSet(${versionPatch})
+
+# Manually generating minor version
+# VersionCalculate()
+ VersionWrite(${versionName} ${export_name} "${ARGN}")
+ENDMACRO()
+
+# This Macro allows you to set the rewrite number
+MACRO(VersionMajorSet versionMajor)
+ SET(vMajor ${versionMajor})
+ENDMACRO()
+
+MACRO(VersionMinorSet versionMinor)
+ SET(vMinor ${versionMinor})
+ENDMACRO(VersionMinorSet)
+
+MACRO(VersionPatchSet versionPatch)
+ SET(vPatch ${versionPatch})
+ENDMACRO(VersionPatchSet)
+
+# This Macro calculates the number of tags from your git repo
+MACRO(VersionCalculate)
+ FIND_PACKAGE(Git)
+ IF(GIT_FOUND)
+ EXEC_PROGRAM(${GIT_EXECUTABLE} ${CMAKE_SOURCE_DIR} ARGS tag OUTPUT_VARIABLE return)
+ STRING(REGEX REPLACE "\n" ";" return "${return}")
+ SET(count 0)
+ FOREACH(r ${return})
+ MATH(EXPR count "${count} + 1")
+ ENDFOREACH()
+ SET(vMinor ${count})
+ ELSE()
+ SET(vMinor "X")
+ ENDIF()
+ENDMACRO()
+
+# This Macro writes your hpp/cpp files
+MACRO(VersionWrite vProjectName export_name)
+ SET(include_list "${ARGN}")
+ FOREACH(il ${include_list})
+ SET(includes "${includes}\n\#include \"${il}\"")
+ ENDFOREACH()
+ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${vProjectName}Version.hpp
+"/* Current Version of ${vProjectName}
+ * Major is: ${vMajor}
+ * Minor is: ${vMinor}
+ * Patch is: ${vPatch}
+ */
+${includes}
+\#include \"ProjectVersion.hpp\"
+extern ${export_name} ProjectVersion ${vProjectName}Version;\n"
+ )
+
+ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${vProjectName}Version.cpp
+"/* Current Version of ${vProjectName}
+ * Make sure to include this file in your built sources
+ */
+\#include \"${vProjectName}Version.hpp\"
+ProjectVersion ${vProjectName}Version = ProjectVersion(\"${vProjectName}\", \"${vMajor}\", \"${vMinor}\", \"${vPatch}\");\n"
+ )
+ENDMACRO()
--- /dev/null
+function(xdmf_create_config_file name)
+ get_cmake_property(ALL_VARS VARIABLES)
+ set(XDMF_VARS "")
+ foreach(var ${ALL_VARS})
+ if (NOT "x${${var}}" STREQUAL "x")
+ string(REGEX REPLACE "\\\\" "\\\\\\\\" ${var} "${${var}}")
+ if (var MATCHES "^(XDMF).*$")
+ set(XDMF_VARS "${XDMF_VARS}\nset(${var}\t\t\"${${var}}\")")
+ else()
+ set(XDMF_VARS "${XDMF_VARS}\nset(XDMF_${var}\t\t\"${${var}}\")")
+ endif()
+ endif()
+ endforeach()
+ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${name}Config.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${name}Config.cmake @ONLY)
+endfunction()
--- /dev/null
+if (FALSE) # XXX(kitware): use VTK's CMake policies
+cmake_minimum_required(VERSION 2.8.5)
+endif ()
+
+project(Xdmf)
+
+
+if(WIN32)
+ ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
+ ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
+endif()
+
+if (FALSE) # XXX(kitware): force settings
+set(XDMF_LIBNAME "Xdmf" CACHE STRING "Name for this xdmf library to avoid collision")
+endif ()
+
+set(XDMF_MAJOR_VERSION 3)
+set(XDMF_MINOR_VERSION 0)
+set(XDMF_PATCH_VERSION 0)
+set(XDMF_VERSION "${XDMF_MAJOR_VERSION}.${XDMF_MINOR_VERSION}.${XDMF_PATCH_VERSION}")
+
+if (FALSE) # XXX(kitware): VTK's module system handles output directories
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
+endif ()
+
+if(BUILD_SHARED_LIBS)
+ set(BUILD_SHARED 1)
+endif()
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XdmfConfig.hpp.in
+ ${CMAKE_CURRENT_BINARY_DIR}/XdmfConfig.hpp)
+
+if (FALSE) # XXX(kitware): force settings
+# Enable CMake testing
+option(XDMF_BUILD_TESTING "Build Tests" OFF)
+if(XDMF_BUILD_TESTING)
+ enable_testing()
+ include(CTest)
+endif()
+else ()
+set(XDMF_BUILD_TESTING OFF)
+endif ()
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+list(APPEND CMAKE_MODULE_PATH
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMake
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/VersionSuite)
+if(XDMF_BUILD_TESTING)
+ list(APPEND CMAKE_MODULE_PATH
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/TestingSuite)
+endif()
+
+include(XdmfFunctions)
+
+# Should we build with documentation
+if (FALSE) # XXX(kitware): force settings
+option(XDMF_BUILD_DOCUMENTATION OFF)
+else ()
+set(XDMF_BUILD_DOCUMENTATION OFF)
+endif ()
+if(XDMF_BUILD_DOCUMENTATION)
+ add_subdirectory(doc)
+endif()
+
+if (FALSE) # XXX(kitware): force settings
+# Wrapper Setup
+option(XDMF_WRAP_PYTHON OFF)
+option(XDMF_WRAP_JAVA OFF)
+else ()
+set(XDMF_WRAP_PYTHON OFF)
+set(XDMF_WRAP_JAVA OFF)
+endif ()
+
+if (FALSE) # XXX(kitware): VTK's module system handles dependencies
+#check for TIFF
+find_package(TIFF)
+if (TIFF_FOUND)
+ add_definitions(-DXDMF_BUILD_TIFF)
+ include_directories(${TIFF_INCLUDE_DIR})
+endif (TIFF_FOUND)
+endif ()
+
+if (FALSE) # XXX(kitware): force settings
+# Test for DSM
+option(XDMF_BUILD_DSM OFF)
+mark_as_advanced(XDMF_BUILD_DSM)
+else ()
+set(XDMF_BUILD_ON OFF)
+endif ()
+if(XDMF_BUILD_DSM)
+ find_package(MPI REQUIRED)
+ if(MPI_FOUND)
+ include_directories(${MPI_INCLUDE_PATH})
+ # The Intel compiler requires an extra tag for CXX_FLAGS in order to properly build.
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
+ add_definitions(-DMPICH_IGNORE_CXX_SEEK)
+ endif ()
+ endif()
+ option(XDMF_BUILD_DSM_THREADS ON)
+ if (XDMF_WRAP_PYTHON)
+ find_path(PYTHON_INCLUDE_MPI4PY_DIR
+ NAMES mpi4py/mpi4py.i
+ DOC "Directory containing the mpi4py/mpi4py.i file")
+ endif ()
+ add_definitions(-DXDMF_BUILD_DSM)
+endif()
+
+# If we are wrapping either, we need swig
+if(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
+ find_package(SWIG 2.0.0 REQUIRED)
+ include(${SWIG_USE_FILE})
+endif()
+
+# If we are wrapping python, let's include it in the top level
+if(XDMF_WRAP_PYTHON)
+ find_package(PythonInterp ${REQUESTED_PYTHON_VERSION} REQUIRED)
+ find_package(PythonLibs ${REQUESTED_PYTHON_VERSION} REQUIRED)
+ if (XDMF_BUILD_DSM)
+ find_package (MPI4PY REQUIRED)
+ if (MPI4PY_FOUND)
+ if ("${PYTHON_INCLUDE_MPI4PY_DIR}" STREQUAL "")
+ set(PYTHON_INCLUDE_MPI4PY_DIR ${MPI4PY_INCLUDE_DIR})
+ endif ()
+ endif ()
+ include_directories(${PYTHON_INCLUDE_DIRS} ${MPI_CXX_INCLUDE_PATH} ${PYTHON_INCLUDE_MPI4PY_DIR})
+ else ()
+ include_directories(${PYTHON_INCLUDE_DIRS})
+ endif ()
+
+ # A macro to swig and create the python files
+ # Since we essentually do the same thing inside and outside core, it
+ # would be easier as a macro
+ # Parameters:
+ # python_name = the name of the intended target to be wrapped
+ # ${ARGN} = any dependencies needed by the target
+ # Output:
+ # Target Name = the output target name will have ${python_name} as its name
+ macro(XDMF_SWIG_PYTHON python_name)
+ set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
+ # optimize swig generation --- these are all flags corresponding to -O
+ # except -fvirtual which breaks visitor operation
+ set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -modern -fastdispatch -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone)
+ #Enables DSM
+ if (XDMF_BUILD_DSM)
+ set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM)
+ if (XDMF_BUILD_DSM_THREADS)
+ set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM_THREADS)
+ endif ()
+ endif ()
+ if (TIFF_FOUND)
+ set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_TIFF)
+ endif ()
+ set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
+ set(swig_extra_generated_files "")
+ swig_add_module(${python_name}Python python ${python_name}.i)
+
+ if (NOT APPLE)
+ swig_link_libraries(${python_name}Python ${python_name} ${PYTHON_LIBRARIES})
+ else ()
+ swig_link_libraries(${python_name}Python ${python_name})
+ endif ()
+
+ set_property(DIRECTORY APPEND PROPERTY
+ ADDITIONAL_MAKE_CLEAN_FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/${python_name}.pyc
+ )
+
+ if("${ARGN}" STRGREATER "")
+ add_dependencies(${python_name} "${ARGN}")
+ endif()
+
+ if(APPLE)
+ set_target_properties(${SWIG_MODULE_${python_name}Python_REAL_NAME}
+ PROPERTIES
+ LINK_FLAGS "-undefined dynamic_lookup")
+ endif()
+
+ set_target_properties(${SWIG_MODULE_${python_name}Python_REAL_NAME}
+ PROPERTIES
+ OUTPUT_NAME "_${python_name}")
+
+ set(
+ PYTHON_INSTALL_DIR
+ ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/xdmf
+ )
+
+ string(TOUPPER ${python_name} python_name_upper)
+ set(${python_name_upper}_PYTHON
+ ${PYTHON_INSTALL_DIR}/${python_name}.py)
+ get_directory_property(${python_name}Parent PARENT_DIRECTORY)
+ if(NOT "${${python_name}Parent}" STREQUAL "")
+ set(${python_name_upper}_PYTHON ${${python_name_upper}_PYTHON}
+ PARENT_SCOPE)
+ endif()
+
+ install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${python_name}.py
+ DESTINATION ${PYTHON_INSTALL_DIR})
+ install(TARGETS ${SWIG_MODULE_${python_name}Python_REAL_NAME}
+ DESTINATION ${PYTHON_INSTALL_DIR})
+ endmacro()
+endif()
+
+# If we are wrapping java, let's include it in the top level
+if(XDMF_WRAP_JAVA)
+ find_package(Java REQUIRED)
+ find_package(JNI REQUIRED)
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${JAVA_INCLUDE_PATH}
+ ${JAVA_INCLUDE_PATH2})
+
+ # A macro to swig and create the jar files
+ # Since we essentually do the same thing inside and outside core, it
+ # would be easier as a macro
+ # Parameters:
+ # java_name = the name of the intended target to be wrapped
+ # ${ARGN} = any dependencies needed by the target
+ # Output:
+ # Target Name = the output target name will have ${java_name}Java as its name
+ # Target Jar = the output target jar will have ${java_name}Java.jar as its name
+ macro(XDMF_SWIG_JAVA java_name)
+ set(${java_name}_JAVA_JAR ${CMAKE_BINARY_DIR}/${java_name}.jar)
+ set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
+ set(XDMF_JAVA_DIR ${CMAKE_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
+ set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
+ set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -v -make_default -package mil.army.arl.xdmf)
+ set_source_files_properties(${java_name}.i PROPERTIES CPLUSPLUS ON)
+ set(swig_extra_generated_files "")
+ swig_add_module(${java_name}Java java ${java_name}.i)
+ swig_link_libraries(${java_name}Java ${java_name})
+
+ if(WIN32)
+ set(java_files *.java)
+ set(java_dest "bin")
+ set(separator "\;")
+ else()
+ set(java_files ${XDMF_JAVA_DIR}/*.java)
+ set(java_dest "lib/java")
+ set(separator ":")
+ endif()
+
+ add_custom_target(${java_name}_Java_Dir ALL DEPENDS ${XDMF_JAVA_DIR})
+ add_custom_command(OUTPUT ${XDMF_JAVA_DIR}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${XDMF_JAVA_DIR})
+ add_custom_target(Compiled_${java_name}_Jar ALL DEPENDS
+ ${${java_name}_JAVA_JAR})
+ add_custom_command(OUTPUT ${${java_name}_JAVA_JAR}
+ COMMAND ${CMAKE_COMMAND} -E chdir ${XDMF_JAVA_PACKAGE_DIR}
+ ${JAVA_COMPILE} -cp \".${java_cp_jars}\" ${java_files}
+ COMMAND ${JAVA_ARCHIVE} -cvf ${${java_name}_JAVA_JAR}
+ "${XDMF_JAVA_PACKAGE_DIR}/*.class")
+ add_dependencies(${java_name}Java ${java_name}_Java_Dir)
+ add_dependencies(Compiled_${java_name}_Jar ${java_name}Java)
+
+ if(NOT ${ARGN} EQUAL "")
+ add_dependencies(Compiled_${java_name}_Jar "${ARGN}")
+ endif()
+
+ set_property(DIRECTORY APPEND PROPERTY
+ ADDITIONAL_MAKE_CLEAN_FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/${java_name}.jar
+ ${XDMF_JAVA_DIR})
+
+ set(java_cp_jars "${java_cp_jars}${separator}${${java_name}_JAVA_JAR}")
+ string(TOUPPER ${java_name} java_name_upper)
+ set(${java_name_upper}_JAVA_JAR
+ ${CMAKE_INSTALL_PREFIX}/lib/java/${java_name}.jar)
+ get_directory_property(${java_name}Parent PARENT_DIRECTORY)
+ if(NOT "${${java_name}Parent}" STREQUAL "")
+ set(${java_name_upper}_JAVA_JAR ${${java_name_upper}_JAVA_JAR}
+ PARENT_SCOPE)
+ set(java_cp_jars "${java_cp_jars}" PARENT_SCOPE)
+ endif()
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${java_name}.jar
+ DESTINATION lib/java)
+ install(TARGETS ${SWIG_MODULE_${java_name}Java_REAL_NAME}
+ DESTINATION ${java_dest})
+ endmacro()
+endif()
+
+include(GNUInstallDirs)
+
+add_subdirectory(core)
+include_directories(${XdmfCore_INCLUDE_DIRS} ${XdmfDSM_INCLUDE_DIRS})
+
+if (FALSE) # XXX(kitware): force settings
+option(XDMF_BUILD_CORE_ONLY OFF)
+mark_as_advanced(XDMF_BUILD_CORE_ONLY)
+else ()
+set(XDMF_BUILD_CORE_ONLY OFF)
+endif ()
+if(NOT XDMF_BUILD_CORE_ONLY)
+ set(XdmfSources
+ XdmfAggregate
+ XdmfAttribute
+ XdmfAttributeCenter
+ XdmfAttributeType
+ XdmfCurvilinearGrid
+ XdmfDomain
+ XdmfGeometry
+ XdmfGeometryType
+ XdmfGraph
+ XdmfGrid
+ XdmfGridCollection
+ XdmfGridCollectionType
+ XdmfGridController
+ XdmfGridTemplate
+ XdmfItemFactory
+ XdmfMap
+ XdmfReader
+ XdmfRectilinearGrid
+ XdmfRegularGrid
+ XdmfSet
+ XdmfSetType
+ XdmfTemplate
+ XdmfTime
+ XdmfTopology
+ XdmfTopologyType
+ XdmfUnstructuredGrid)
+
+ if (FALSE)
+ add_library(${XDMF_LIBNAME} ${XdmfSources})
+ SET_TARGET_PROPERTIES(
+ ${XDMF_LIBNAME} PROPERTIES
+ VERSION ${XDMF_VERSION}
+ SOVERSION ${XDMF_MAJOR_VERSION}
+ )
+ if(XDMF_BUILD_DSM)
+ target_link_libraries(${XDMF_LIBNAME} XdmfCore XdmfDSM)
+ else(XDMF_BUILD_DSM)
+ target_link_libraries(${XDMF_LIBNAME} XdmfCore)
+ endif(XDMF_BUILD_DSM)
+ else ()
+ set(sources)
+ set(headers)
+ foreach (xdmf_source IN LISTS XdmfSources)
+ list(APPEND sources
+ "${xdmf_source}.cpp")
+ list(APPEND headers
+ "${xdmf_source}.hpp")
+ endforeach ()
+
+ vtk_module_add_module(VTK::xdmf3
+ SOURCES ${sources}
+ HEADERS ${headers}
+ HEADERS_SUBDIR "vtkxdmf3")
+ target_link_libraries(xdmf3
+ PUBLIC
+ vtkxdmfcore)
+ endif ()
+
+ if(WIN32)
+ if (BUILD_SHARED_LIBS)
+ # XXX(kitware) using correct target name
+ set_target_properties(xdmf3 PROPERTIES
+ DEFINE_SYMBOL XDMF_EXPORTS)
+ endif ()
+ endif()
+
+ if(XDMF_WRAP_JAVA)
+ XDMF_SWIG_JAVA(${XDMF_LIBNAME} Compiled_XdmfCore_Jar)
+ endif()
+
+ if(XDMF_WRAP_PYTHON)
+ if (NOT BUILD_SHARED_LIBS)
+ message(FATAL_ERROR "Python Wrappers do not function"
+ " properly without shared libraries")
+ endif (NOT BUILD_SHARED_LIBS)
+ if (XDMF_BUILD_DSM)
+ XDMF_SWIG_PYTHON(${XDMF_LIBNAME} XdmfCore XdmfDSM)
+ else()
+ XDMF_SWIG_PYTHON(${XDMF_LIBNAME} XdmfCore)
+ endif()
+ set(
+ XDMF_PYTHON_INSTALL_DIR
+ ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/xdmf
+ )
+ endif()
+
+ if(XDMF_BUILD_TESTING)
+ add_subdirectory(tests)
+ endif()
+
+ if (FALSE) # XXX(kitware): force settings
+ option(XDMF_BUILD_UTILS OFF)
+ else ()
+ set(XDMF_BUILD_UTILS OFF)
+ endif ()
+ if(XDMF_BUILD_UTILS)
+ add_subdirectory(utils)
+ endif()
+
+ if (FALSE) # XXX(kitware): VTK's module system handles installation
+ file(GLOB XdmfHeaders
+ "*.hpp"
+ "*.tpp"
+ "*.i"
+ "${CMAKE_CURRENT_BINARY_DIR}/*.hpp"
+ )
+ install(FILES ${XdmfHeaders} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+ install(TARGETS ${XDMF_LIBNAME}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+ endif ()
+endif()
+
+if(WIN32 AND NOT CYGWIN)
+ set(DEF_INSTALL_CMAKE_DIR CMake)
+else()
+ set(DEF_INSTALL_CMAKE_DIR
+ "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
+endif()
+if (FALSE) # XXX(kitware): VTK's module system handles installation
+xdmf_create_config_file(${PROJECT_NAME})
+install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
+ DESTINATION ${DEF_INSTALL_CMAKE_DIR})
+endif ()
--- /dev/null
+Copyright (c) 2011 U.S. Army Research Laboratory
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of the U.S. Army Research Laboratory nor the names
+ of any contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ * Modified source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : Xdmf.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef _XDMF_HPP
+#define _XDMF_HPP
+
+/*! \mainpage XDMF API
+*
+* \section intro Introduction
+*
+* The eXtensible Data Model and Format (XDMF) is a distributed data
+* hub for accessing scientific data in High Performance Computing
+* (HPC) applications. XDMF defines a data model and format as well as
+* facilities for accessing the data in a distributed environment.
+*
+* XDMF differs from other data model and format efforts in that the
+* "light data" is logically (and possibly physically) separated from
+* the "heavy data". Light data is considered to be both "data about
+* the data" such as dimensions and name, as well as small quantities
+* of computed data. Heavy data is considered to be large amounts of
+* data. For example, in a three dimensional structural mechanics
+* calculation, the size and dimensions of the computational grid are
+* light data while the actual X, Y, and Z values for the grid are
+* heavy data. Calculated values like "Pressure at a node" are heavy,
+* while "Total Residual Mass" for the entire calculation is light.
+* Light data is stored on disk in a machine parsable language like
+* XML. Heavy data is stored in a format suitable for large amounts of
+* data like HDF5.
+*
+* While use of the XDMF API is not necessary to produce or consume
+* valid datasets, it is extremely useful for handling the wide variety
+* of files that are possible and its use is highly recommended. The
+* XDMF API is written in C++ and is wrapped for access from other
+* languages including Python and Java.
+*
+* XDMF utilizes reference counting shared pointers to handle ownership
+* of XDMF objects. This allows multiple objects to reference a single
+* XDMF object. An object is deleted and memory is reclaimed when no
+* other XDMF objects hold a reference to the object. This allows
+* flexibility in constructing XDMF structures, as simple structures
+* can be shared instead of copied.
+*
+* All XDMF objects are constructed by calling New(), which returns a
+* shared pointer to a newly constructed object. All default
+* constructors in the XDMF API are protected, ensuring that only
+* shared pointers can be created. These pointers are freed
+* automatically by the shared pointer reference counting mechanism.
+*
+*
+* Structure:
+*
+* Xdmf2 is structured in a tree format with an XdmfDomain serving
+* as the base. The Domain contains multiple grid collections or
+* grids; each with their own geometries, topologies, attributes,
+* and/or sets. With the inclusion of shared pointers in Xdmf2
+* a topology could be shared across multiple grids or a grid
+* could be included in multiple grid collections and/or the domain.
+*
+* Comparing objects is done by comparing pointer addresses,
+* a deep copy will not produce an equivalent object.
+*
+*
+* C++ Examples:
+*
+* \subpage cppwrite "C++ Example of Xdmf Creation"
+*
+* \subpage cppread "C++ Example of Reading Xdmf"
+*
+* \subpage cppedit "C++ Example of Reading and Modifying Xdmf"
+*
+* Python Examples:
+*
+* \subpage pywrite "Python Example of Xdmf Creation"
+*
+* \subpage pyread "Python Example of Reading Xdmf"
+*
+* \subpage pyedit "Python Example of Reading and Modifying Xdmf"
+*
+*/
+
+/*!
+* \page cppwrite Example of Xdmf Creation
+* \include ExampleXdmfWrite.cpp
+*/
+
+/*!
+* \page cppread Example of Reading Xdmf
+* \include ExampleXdmfRead.cpp
+*/
+
+/*!
+* \page cppedit Example of Reading and Modifying
+* \include ExampleXdmfEdit.cpp
+*/
+
+/*!
+* \page pywrite Example of Xdmf Creation
+* \include XdmfExampleWrite.py
+*/
+
+/*!
+* \page pyread Example of Reading Xdmf
+* \include XdmfExampleRead.py
+*/
+
+/*!
+* \page pyedit Example of Reading and Modifying
+* \include XdmfExampleEdit.py
+*/
+
+#include "XdmfConfig.hpp"
+
+
+/* Keep all our Win32 Conversions here */
+#ifdef _WIN32
+#ifdef XDMFSTATIC
+# define XDMFCORE_EXPORT
+# define XDMFDSM_EXPORT
+# define XDMF_EXPORT
+# define XDMFCORE_TEMPLATE
+# define XDMFDSM_TEMPLATE
+# define XDMF_TEMPLATE
+#else
+/* Used to export/import from the dlls */
+# undef XDMFCORE_EXPORT
+# define XDMFCORE_EXPORT __declspec(dllimport)
+# undef XDMFCORE_TEMPLATE
+# define XDMFCORE_TEMPLATE extern
+
+# undef XDMFDSM_EXPORT
+# define XDMFDSM_EXPORT __declspec(dllimport)
+# undef XDMFDSM_TEMPLATE
+# define XDMFDSM_TEMPLATE extern
+
+# undef XDMFUTILS_EXPORT
+# define XDMFUTILS_EXPORT __declspec(dllimport)
+# undef XDMFUTILS_TEMPLATE
+# define XDMFUTILS_TEMPLATE extern
+
+# ifdef XDMF_EXPORTS
+# define XDMF_EXPORT __declspec(dllexport)
+# define XDMF_TEMPLATE
+# else /* XDMF_EXPORTS */
+# define XDMF_EXPORT __declspec(dllimport)
+# define XDMF_TEMPLATE extern
+# endif /* XDMF_EXPORTS */
+#endif /* XDMFSTATIC */
+
+/* Compiler Warnings */
+#ifndef XDMF_DEBUG
+#pragma warning( disable : 4231 ) /* nonstandard extension used : 'extern' before template explicit instantiation */
+#pragma warning( disable : 4251 ) /* needs to have dll-interface to be used by clients (Most of these guys are in private */
+#pragma warning( disable : 4275 ) /* non dll-interface class 'std::_Container_base_aux' used as base for dll-interface class */
+#pragma warning( disable : 4373 ) /* virtual function overrides, parameters only differed by const/volatile qualifiers */
+#pragma warning( disable : 4748 ) /* /GS can not protect parameters and local variables from local buffer overrun (turned off op)*/
+#endif /* XDMF_DEBUG */
+
+/* Compiler Optimizations will result in an 'internal compiler error', so turn them off */
+#pragma optimize("g", off)
+
+#pragma warning( disable : 4297 ) /* __declspec(nothrow), throw(), noexcept(true), or noexcept was specified in the function */
+#pragma warning( disable : 4800 ) /* 'int': forcing value to bool 'true' or 'false' (performance warning) */
+#pragma warning( disable : 4250 ) /* inherits insert via dominance */
+#pragma warning( disable : 4521 ) /* multiple copy constructors */
+
+#else /* _WIN32 */
+/* We don't need to export/import since there are no dlls */
+#define XDMFCORE_EXPORT
+#define XDMFDSM_EXPORT
+#define XDMF_EXPORT
+#define XDMFCORE_TEMPLATE
+#define XDMFDSM_TEMPLATE
+#define XDMF_TEMPLATE
+#endif /* _WIN32 */
+#endif /* _XDMF_HPP */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAggregate.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <numeric>
+#include <functional>
+#include <boost/tokenizer.hpp>
+#include "XdmfArray.hpp"
+#include "XdmfError.hpp"
+#include "XdmfAggregate.hpp"
+#include "XdmfVisitor.hpp"
+#include "XdmfWriter.hpp"
+#include "string.h"
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfAggregate, XdmfArray, Array, Name)
+
+XdmfAggregate::XdmfAggregate()
+{
+}
+
+XdmfAggregate::XdmfAggregate(XdmfAggregate & refAggregate) :
+ XdmfArrayReference(refAggregate)
+{
+}
+
+XdmfAggregate::~XdmfAggregate()
+{
+}
+
+const std::string XdmfAggregate::ItemTag = "Aggregate";
+
+shared_ptr<XdmfAggregate>
+XdmfAggregate::New()
+{
+ shared_ptr<XdmfAggregate> p(new XdmfAggregate());
+ return p;
+}
+
+std::vector<unsigned int> XdmfAggregate::getDimensions() const
+{
+ std::vector<unsigned int> testDims = mArrays[0]->getDimensions();
+
+ bool isSame = true;
+
+ for(std::vector<shared_ptr<XdmfArray> >::const_iterator iter =
+ mArrays.begin();
+ iter != mArrays.end() && isSame;
+ ++iter) {
+ std::vector<unsigned int> compareDims = (*iter)->getDimensions();
+ if (compareDims.size() == testDims.size())
+ {
+ for (unsigned int i = 0; i < testDims.size(); ++i)
+ {
+ if (compareDims[i] != testDims[i])
+ {
+ isSame = false;
+ break;
+ }
+ }
+ }
+ else
+ {
+ isSame = false;
+ break;
+ }
+ }
+
+ if (isSame)
+ {
+ testDims.push_back(mArrays.size());
+ return testDims;
+ }
+ else
+ {
+ std::vector<unsigned int> returnDims;
+ returnDims.push_back(this->getSize());
+ return returnDims;
+ }
+}
+
+std::map<std::string, std::string>
+XdmfAggregate::getItemProperties() const
+{
+ std::map<std::string, std::string> aggregateMap = XdmfArrayReference::getItemProperties();
+
+ return aggregateMap;
+}
+
+std::string
+XdmfAggregate::getItemTag() const
+{
+ return ItemTag;
+}
+
+unsigned int
+XdmfAggregate::getSize() const
+{
+ unsigned int total = 0;
+ for(std::vector<shared_ptr<XdmfArray> >::const_iterator iter =
+ mArrays.begin();
+ iter != mArrays.end();
+ ++iter) {
+ total += (*iter)->getSize();
+ }
+ return total;
+}
+
+void
+XdmfAggregate::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ bool placeholderFound = false;
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ if (!placeholderFound) {
+ placeholderFound = true;
+ }
+ else {
+ this->insert(array);
+ }
+/*
+ this->swap(array);
+ if (array->getReference()) {
+ this->setReference(array->getReference());
+ this->setReadMode(XdmfArray::Reference);
+ }
+ break;
+*/
+ }
+ }
+}
+
+shared_ptr<XdmfArray>
+XdmfAggregate::read() const
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+
+ if (mArrays.size() > 0)
+ {
+ if (!mArrays[0]->isInitialized()) {
+ mArrays[0]->read();
+ }
+ returnArray->insert(0, mArrays[0], 0, mArrays[0]->getSize(), 1, 1);
+ if (mArrays.size() > 1)
+ {
+ unsigned int offset = mArrays[0]->getSize();
+ for (unsigned int i = 1; i < mArrays.size(); ++i)
+ {
+ if (!mArrays[i]->isInitialized()) {
+ mArrays[i]->read();
+ }
+ returnArray->insert(offset, mArrays[i], 0, mArrays[i]->getSize(), 1, 1);
+ offset += mArrays[i]->getSize();
+ }
+ }
+ }
+
+ return returnArray;
+}
+
+void
+XdmfAggregate::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+
+ bool originalXPath;
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ originalXPath = writer->getWriteXPaths();
+ writer->setWriteXPaths(false);
+ }
+
+ shared_ptr<XdmfArray> spacerarray = XdmfArray::New();
+ spacerarray->pushBack((int)0);
+ spacerarray->accept(visitor);
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ writer->setWriteXPaths(originalXPath);
+ }
+
+ for (unsigned int i = 0; i < mArrays.size(); ++i)
+ {
+ mArrays[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+XDMFAGGREGATE * XdmfAggregateNew()
+{
+ try
+ {
+ shared_ptr<XdmfAggregate> generatedAggregate = XdmfAggregate::New();
+ return (XDMFAGGREGATE *)((void *)(new XdmfAggregate(*generatedAggregate.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfAggregate> generatedAggregate = XdmfAggregate::New();
+ return (XDMFAGGREGATE *)((void *)(new XdmfAggregate(*generatedAggregate.get())));
+ }
+}
+
+XDMFARRAY *
+XdmfAggregateGetArray(XDMFAGGREGATE * aggregate, unsigned int index)
+{
+ return (XDMFARRAY *)((void *)(((XdmfAggregate *)(aggregate))->getArray(index).get()));
+}
+
+XDMFARRAY *
+XdmfAggregateGetArrayByName(XDMFAGGREGATE * aggregate, char * name)
+{
+ return (XDMFARRAY *)((void *)(((XdmfAggregate *)(aggregate))->getArray(name).get()));
+}
+
+unsigned int
+XdmfAggregateGetNumberArrays(XDMFAGGREGATE * aggregate)
+{
+ return ((XdmfAggregate *)(aggregate))->getNumberArrays();
+}
+
+void
+XdmfAggregateInsertArray(XDMFAGGREGATE * aggregate, XDMFARRAY * array, int transferOwnership)
+{
+ if (transferOwnership) {
+ ((XdmfAggregate *)(aggregate))->insert(shared_ptr<XdmfArray>((XdmfArray *)array));
+ }
+ else {
+ ((XdmfAggregate *)(aggregate))->insert(shared_ptr<XdmfArray>((XdmfArray *)array, XdmfNullDeleter()));
+ }
+}
+
+void
+XdmfAggregateRemoveArray(XDMFAGGREGATE * aggregate, unsigned int index)
+{
+ ((XdmfAggregate *)(aggregate))->removeArray(index);
+}
+
+void
+XdmfAggregateRemoveArrayByName(XDMFAGGREGATE * aggregate, char * name)
+{
+ ((XdmfAggregate *)(aggregate))->removeArray(name);
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfAggregate, XDMFAGGREGATE)
+XDMF_ARRAYREFERENCE_C_CHILD_WRAPPER(XdmfAggregate, XDMFAGGREGATE)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAggregate.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFAGGREGATE_HPP_
+#define XDMFAGGREGATE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfArrayReference.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+// Includes
+#include <vector>
+#include "XdmfItem.hpp"
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief Couples an XdmfArray with heavy data stored in another XdmfArray.
+ *
+ * This class serves to allow an array to retrieve data that is a subsection
+ * of an already existing array.
+ */
+class XDMF_EXPORT XdmfAggregate: public XdmfArrayReference {
+
+public:
+
+ /**
+ * Generates an XdmfAggregate object.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAggregate.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAggregate.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return A constructed XdmfAggregate object.
+ */
+ static shared_ptr<XdmfAggregate>
+ New();
+
+ virtual ~XdmfAggregate();
+
+ LOKI_DEFINE_VISITABLE(XdmfAggregate, XdmfItem)
+ XDMF_CHILDREN(XdmfAggregate, XdmfArray, Array, Name)
+
+ static const std::string ItemTag;
+
+ /**
+ * Get the dimensions of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAggregate.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAggregate.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return A vector containing the size in each dimension of the
+ * set referenced by this subset.
+ */
+ std::vector<unsigned int> getDimensions() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the size of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAggregate.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getSize
+ * @until //#getSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAggregate.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getSize
+ * @until #//getSize
+ *
+ * @return An int containing the size of the subset.
+ */
+ unsigned int getSize() const;
+
+ /**
+ * Read data reference by this subset and return as an XdmfArray.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAggregate.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAggregate.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//read
+ * @until #//read
+ *
+ * @return An array filled with data based on the subset's parameters.
+ */
+ virtual shared_ptr<XdmfArray> read() const;
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfAggregate(XdmfAggregate&);
+
+protected:
+
+ XdmfAggregate();
+
+ void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfAggregate(const XdmfAggregate&); // Not implemented.
+ void operator=(const XdmfAggregate&); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFAGGREGATE; // Simply as a typedef to ensure correct typing
+typedef struct XDMFAGGREGATE XDMFAGGREGATE;
+
+XDMF_EXPORT XDMFAGGREGATE * XdmfAggregateNew();
+
+XDMF_EXPORT XDMFARRAY * XdmfAggregateGetArray(XDMFAGGREGATE * aggregate, unsigned int index);
+
+XDMF_EXPORT XDMFARRAY * XdmfAggregateGetArrayByName(XDMFAGGREGATE * aggregate, char * name);
+
+XDMF_EXPORT unsigned int XdmfAggregateGetNumberArrays(XDMFAGGREGATE * aggregate);
+
+XDMF_EXPORT void XdmfAggregateInsertArray(XDMFAGGREGATE * aggregate, XDMFARRAY * array, int transferOwnership);
+
+XDMF_EXPORT void XdmfAggregateRemoveArray(XDMFAGGREGATE * aggregate, unsigned int index);
+
+XDMF_EXPORT void XdmfAggregateRemoveArrayByName(XDMFAGGREGATE * aggregate, char * name);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfAggregate, XDMFAGGREGATE, XDMF)
+XDMF_ARRAYREFERENCE_C_CHILD_DECLARE(XdmfAggregate, XDMFAGGREGATE, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFAGGREGATE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAttribute.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+
+#include <utility>
+#include "XdmfAttribute.hpp"
+#include "XdmfAttributeCenter.hpp"
+#include "XdmfAttributeType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfArray.hpp"
+
+#include <sstream>
+//-----------------------------------------------------------------------------
+XDMF_CHILDREN_IMPLEMENTATION(XdmfAttribute, XdmfArray, AuxiliaryArray, Name)
+//-----------------------------------------------------------------------------
+shared_ptr<XdmfAttribute>
+XdmfAttribute::New()
+{
+ shared_ptr<XdmfAttribute> p(new XdmfAttribute());
+ return p;
+}
+//-----------------------------------------------------------------------------
+XdmfAttribute::XdmfAttribute() :
+ mCenter(XdmfAttributeCenter::Grid()),
+ mName(""),
+ mType(XdmfAttributeType::NoAttributeType()),
+ mItemType(""),
+ mElementDegree(0),
+ mElementFamily(""),
+ mElementCell("")
+{
+}
+//-----------------------------------------------------------------------------
+XdmfAttribute::XdmfAttribute(XdmfAttribute & refAttribute) :
+ XdmfArray(refAttribute),
+ mCenter(refAttribute.mCenter),
+ mName(refAttribute.mName),
+ mType(refAttribute.mType),
+ mItemType(refAttribute.mItemType),
+ mElementDegree(refAttribute.mElementDegree),
+ mElementFamily(refAttribute.mElementFamily),
+ mElementCell(refAttribute.mElementCell)
+{
+}
+//-----------------------------------------------------------------------------
+XdmfAttribute::~XdmfAttribute()
+{
+}
+//-----------------------------------------------------------------------------
+const std::string XdmfAttribute::ItemTag = "Attribute";
+//-----------------------------------------------------------------------------
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttribute::getCenter() const
+{
+ return mCenter;
+}
+//-----------------------------------------------------------------------------
+std::map<std::string, std::string>
+XdmfAttribute::getItemProperties() const
+{
+ std::map<std::string, std::string> attributeProperties;
+ attributeProperties.insert(std::make_pair("Name", mName));
+ mType->getProperties(attributeProperties);
+ mCenter->getProperties(attributeProperties);
+ attributeProperties.insert(std::make_pair("ItemType", mItemType));
+
+ std::stringstream elemDeg;
+ elemDeg << mElementDegree;
+
+ attributeProperties.insert(std::make_pair("ElementDegree",
+ elemDeg.str()));
+
+ attributeProperties.insert(std::make_pair("ElementFamily", mElementFamily));
+ attributeProperties.insert(std::make_pair("ElementCell", mElementCell));
+ return attributeProperties;
+}
+//-----------------------------------------------------------------------------
+std::string
+XdmfAttribute::getItemTag() const
+{
+ return ItemTag;
+}
+//-----------------------------------------------------------------------------
+std::string
+XdmfAttribute::getName() const
+{
+ return mName;
+}
+//-----------------------------------------------------------------------------
+shared_ptr<const XdmfAttributeType>
+XdmfAttribute::getType() const
+{
+ return mType;
+}
+//-----------------------------------------------------------------------------
+std::string XdmfAttribute::getItemType() const
+{
+ return mItemType;
+}
+//-----------------------------------------------------------------------------
+unsigned int XdmfAttribute::getElementDegree() const
+{
+ return mElementDegree;
+}
+//-----------------------------------------------------------------------------
+std::string XdmfAttribute::getElementFamily() const
+{
+ return mElementFamily;
+}
+//-----------------------------------------------------------------------------
+std::string XdmfAttribute::getElementCell() const
+{
+ return mElementCell;
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::populateItem(
+ const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+
+ std::map<std::string, std::string>::const_iterator name =
+ itemProperties.find("Name");
+ if(name != itemProperties.end()) {
+ mName = name->second;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'Name' not found in itemProperties in "
+ "XdmfAttribute::populateItem");
+ }
+
+ mCenter = XdmfAttributeCenter::New(itemProperties);
+ mType = XdmfAttributeType::New(itemProperties);
+
+ std::map<std::string, std::string>::const_iterator element_degree =
+ itemProperties.find("ElementDegree");
+ if(element_degree != itemProperties.end()) {
+ mElementDegree = atoi(element_degree->second.c_str());
+ }
+
+ std::map<std::string, std::string>::const_iterator element_family =
+ itemProperties.find("ElementFamily");
+ if(element_family != itemProperties.end()) {
+ mElementFamily = element_family->second;
+ }
+
+ std::map<std::string, std::string>::const_iterator element_cell =
+ itemProperties.find("ElementCell");
+ if(element_cell != itemProperties.end()) {
+ mElementCell = element_cell->second;
+ }
+
+ std::map<std::string, std::string>::const_iterator item_type =
+ itemProperties.find("ItemType");
+ if(item_type != itemProperties.end()) {
+ mItemType = item_type->second;
+ }
+
+ bool first = true;
+ for (std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin(); iter != childItems.end(); ++iter) {
+ if (shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter))
+ {
+ if (first)
+ {
+ first = false;
+ this->swap(array);
+ if (array->getReference())
+ {
+ this->setReference(array->getReference());
+ this->setReadMode(XdmfArray::Reference);
+ }
+ }
+ else
+ {
+ this->insert(array);
+ }
+ }
+ }
+
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfArray::traverse(visitor);
+ for (unsigned int i = 0; i < mAuxiliaryArrays.size(); ++i)
+ {
+ mAuxiliaryArrays[i]->accept(visitor);
+ }
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setCenter(const shared_ptr<const XdmfAttributeCenter> center)
+{
+ mCenter = center;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setName(const std::string & name)
+{
+ mName = name;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setType(const shared_ptr<const XdmfAttributeType> type)
+{
+ mType = type;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setItemType(std::string type)
+{
+ mItemType = type;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setElementDegree(unsigned int degree)
+{
+ mElementDegree = degree;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setElementFamily(std::string family)
+{
+ mElementFamily = family;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+void
+XdmfAttribute::setElementCell(std::string cell)
+{
+ mElementCell = cell;
+ this->setIsChanged(true);
+}
+//-----------------------------------------------------------------------------
+// C Wrappers
+//-----------------------------------------------------------------------------
+XDMFATTRIBUTE * XdmfAttributeNew()
+{
+ try
+ {
+ shared_ptr<XdmfAttribute> generatedAttribute = XdmfAttribute::New();
+ return (XDMFATTRIBUTE *)((void *)(new XdmfAttribute(*generatedAttribute.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfAttribute> generatedAttribute = XdmfAttribute::New();
+ return (XDMFATTRIBUTE *)((void *)(new XdmfAttribute(*generatedAttribute.get())));
+ }
+}
+//-----------------------------------------------------------------------------
+int XdmfAttributeGetCenter(XDMFATTRIBUTE * attribute)
+{
+ if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Grid()) {
+ return XDMF_ATTRIBUTE_CENTER_GRID;
+ }
+ else if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Cell()) {
+ return XDMF_ATTRIBUTE_CENTER_CELL;
+ }
+ else if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Face()) {
+ return XDMF_ATTRIBUTE_CENTER_FACE;
+ }
+ else if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Edge()) {
+ return XDMF_ATTRIBUTE_CENTER_EDGE;
+ }
+ else if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Node()) {
+ return XDMF_ATTRIBUTE_CENTER_NODE;
+ }
+ else if (((XdmfAttribute *)attribute)->getCenter() ==
+ XdmfAttributeCenter::Other()) {
+ return XDMF_ATTRIBUTE_CENTER_OTHER;
+ }
+ else {
+ return -1;
+ }
+}
+//-----------------------------------------------------------------------------
+int XdmfAttributeGetType(XDMFATTRIBUTE * attribute)
+{
+ if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::Scalar()) {
+ return XDMF_ATTRIBUTE_TYPE_SCALAR;
+ }
+ else if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::Vector()) {
+ return XDMF_ATTRIBUTE_TYPE_VECTOR;
+ }
+ else if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::Tensor()) {
+ return XDMF_ATTRIBUTE_TYPE_TENSOR;
+ }
+ else if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::Matrix()) {
+ return XDMF_ATTRIBUTE_TYPE_MATRIX;
+ }
+ else if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::Tensor6()) {
+ return XDMF_ATTRIBUTE_TYPE_TENSOR6;
+ }
+ else if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::GlobalId()) {
+ return XDMF_ATTRIBUTE_TYPE_GLOBALID;
+ }
+ else if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::NoAttributeType()) {
+ return XDMF_ATTRIBUTE_TYPE_NOTYPE;
+ }
+ else {
+ return -1;
+ }
+}
+//-----------------------------------------------------------------------------
+void XdmfAttributeSetCenter(XDMFATTRIBUTE * attribute, int center, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch(center) {
+ case XDMF_ATTRIBUTE_CENTER_GRID:
+ ((XdmfAttribute *)attribute)->setCenter(XdmfAttributeCenter::Grid());
+ break;
+ case XDMF_ATTRIBUTE_CENTER_CELL:
+ ((XdmfAttribute *)attribute)->setCenter(XdmfAttributeCenter::Cell());
+ break;
+ case XDMF_ATTRIBUTE_CENTER_FACE:
+ ((XdmfAttribute *)attribute)->setCenter(XdmfAttributeCenter::Face());
+ break;
+ case XDMF_ATTRIBUTE_CENTER_EDGE:
+ ((XdmfAttribute *)attribute)->setCenter(XdmfAttributeCenter::Edge());
+ break;
+ case XDMF_ATTRIBUTE_CENTER_NODE:
+ ((XdmfAttribute *)attribute)->setCenter(XdmfAttributeCenter::Node());
+ break;
+ default:
+ {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Attribute Center: Code " << center;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+//-----------------------------------------------------------------------------
+void XdmfAttributeSetType(XDMFATTRIBUTE * attribute, int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch(type) {
+ case XDMF_ATTRIBUTE_TYPE_SCALAR:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::Scalar());
+ break;
+ case XDMF_ATTRIBUTE_TYPE_VECTOR:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::Vector());
+ break;
+ case XDMF_ATTRIBUTE_TYPE_TENSOR:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::Tensor());
+ break;
+ case XDMF_ATTRIBUTE_TYPE_MATRIX:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::Matrix());
+ break;
+ case XDMF_ATTRIBUTE_TYPE_TENSOR6:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::Tensor6());
+ break;
+ case XDMF_ATTRIBUTE_TYPE_GLOBALID:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::GlobalId());
+ break;
+ case XDMF_ATTRIBUTE_TYPE_NOTYPE:
+ ((XdmfAttribute *)attribute)->setType(XdmfAttributeType::NoAttributeType());
+ break;
+ default:
+ {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Attribute Type: Code " << type;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+//-----------------------------------------------------------------------------
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfAttribute, XDMFATTRIBUTE)
+XDMF_ARRAY_C_CHILD_WRAPPER(XdmfAttribute, XDMFATTRIBUTE)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAttribute.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFATTRIBUTE_HPP_
+#define XDMFATTRIBUTE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfAttributeCenter.hpp"
+#include "XdmfAttributeType.hpp"
+#include "XdmfTime.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Holds values located at specific parts of an XdmfGrid.
+ *
+ * XdmfAttribute holds values centered at specific locations of an
+ * XdmfGrid. An attribute contains two properties that should be set,
+ * XdmfAttributeCenter, which describes where the values are centered,
+ * and XdmfAttributeType, which describes what types of values the
+ * attribute contains.
+ */
+class XDMF_EXPORT XdmfAttribute : public XdmfArray {
+
+public:
+
+ /**
+ * Create a new XdmfAttribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfAttribute.
+ */
+ static shared_ptr<XdmfAttribute> New();
+
+ virtual ~XdmfAttribute();
+
+ LOKI_DEFINE_VISITABLE(XdmfAttribute, XdmfArray)
+ XDMF_CHILDREN(XdmfAttribute, XdmfArray, AuxiliaryArray, Name)
+ static const std::string ItemTag;
+
+ using XdmfArray::insert;
+
+#if defined(SWIG)
+ using XdmfItem::insert;
+#endif
+
+ /**
+ * Get the XdmfAttributeCenter associated with this attribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setCenter
+ * @until //#setCenter
+ * @skipline //#getCenter
+ * @until //#getCenter
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setCenter
+ * @until #//setCenter
+ * @skipline #//getCenter
+ * @until #//getCenter
+ *
+ * @return XdmfAttributeCenter of the attribute.
+ */
+ shared_ptr<const XdmfAttributeCenter> getCenter() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the name of the attribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return A string containing the name of the attribute.
+ */
+ std::string getName() const;
+
+ /**
+ * Get the XdmfAttributeType associated with this attribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setType
+ * @until //#setType
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setType
+ * @until #//setType
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * @return XdmfAttributeType of the attribute.
+ */
+ shared_ptr<const XdmfAttributeType> getType() const;
+
+ /**
+ * Get the ItemType associated with this attribute.
+ *
+ * @return ItemType of the attribute.
+ */
+ std::string getItemType() const;
+
+ /**
+ * Get the ElementFamily associated with this attribute.
+ *
+ * @return ElementFamily of the attribute.
+ */
+ std::string getElementFamily() const;
+
+ /**
+ * Get the ElementDegree associated with this attribute.
+ *
+ * @return ElementDegree of the attribute.
+ */
+ unsigned int getElementDegree() const;
+
+ /**
+ * Get the ElementCell associated with this attribute.
+ *
+ * @return ElementCell of the attribute.
+ */
+ std::string getElementCell() const;
+
+ /**
+ * Set the XdmfAttributeCenter associated with this attribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setCenter
+ * @until //#setCenter
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setCenter
+ * @until #//setCenter
+ *
+ * @param center The XdmfAttributeCenter to set.
+ */
+ void setCenter(const shared_ptr<const XdmfAttributeCenter> center);
+
+ /**
+ * Set the name of the attribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ *
+ * @param name A string containing the name to set.
+ */
+ void setName(const std::string & name);
+
+ /**
+ * Set the XdmfAttributeType associated with this attribute.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setType
+ * @until //#setType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setType
+ * @until #//setType
+ *
+ * @param type XdmfAttributeType to set.
+ */
+ void setType(const shared_ptr<const XdmfAttributeType> type);
+
+ /**
+ * Set the ItemType associated with this attribute.
+ *
+ * @param type ItemType to set.
+ */
+ void setItemType(std::string type);
+
+ /**
+ * Set the ElementFamily associated with this attribute.
+ *
+ * @param type ElementFamily to set.
+ */
+ void setElementFamily(std::string type);
+
+ /**
+ * Set the ElementDegree associated with this attribute.
+ *
+ * @param type ElementDegree to set.
+ */
+ void setElementDegree(unsigned int degree);
+
+ /**
+ * Set the ElementCell associated with this attribute.
+ *
+ * @param type ElementCell to set.
+ */
+ void setElementCell(std::string cell);
+
+ XdmfAttribute(XdmfAttribute &);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+protected:
+
+ XdmfAttribute();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfAttribute(const XdmfAttribute &); // Not implemented.
+ void operator=(const XdmfAttribute &); // Not implemented.
+
+ shared_ptr<const XdmfAttributeCenter> mCenter;
+ std::string mName;
+ shared_ptr<const XdmfAttributeType> mType;
+ std::string mItemType;
+ unsigned int mElementDegree;
+ std::string mElementFamily;
+ std::string mElementCell;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFATTRIBUTE; // Simply as a typedef to ensure correct typing
+typedef struct XDMFATTRIBUTE XDMFATTRIBUTE;
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfAttributeNew();
+
+XDMF_EXPORT int XdmfAttributeGetCenter(XDMFATTRIBUTE * attribute);
+
+XDMF_EXPORT int XdmfAttributeGetType(XDMFATTRIBUTE * attribute);
+
+XDMF_EXPORT void XdmfAttributeSetCenter(XDMFATTRIBUTE * attribute, int center, int * status);
+
+XDMF_EXPORT void XdmfAttributeSetType(XDMFATTRIBUTE * attribute, int type, int * status);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfAttribute, XDMFATTRIBUTE, XDMF)
+XDMF_ARRAY_C_CHILD_DECLARE(XdmfAttribute, XDMFATTRIBUTE, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFATTRIBUTE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAttributeCenter.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfAttributeCenter.hpp"
+#include "XdmfError.hpp"
+
+std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()> XdmfAttributeCenter::mAttributeCenterDefinitions;
+
+// Supported XdmfAttributeCenters
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::Grid()
+{
+ static shared_ptr<const XdmfAttributeCenter>
+ p(new XdmfAttributeCenter("Grid"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::Cell()
+{
+ static shared_ptr<const XdmfAttributeCenter>
+ p(new XdmfAttributeCenter("Cell"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::Face()
+{
+ static shared_ptr<const XdmfAttributeCenter>
+ p(new XdmfAttributeCenter("Face"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::Edge()
+{
+ static shared_ptr<const XdmfAttributeCenter>
+ p(new XdmfAttributeCenter("Edge"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::Node()
+{
+ static shared_ptr<const XdmfAttributeCenter>
+ p(new XdmfAttributeCenter("Node"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::Other()
+{
+ static shared_ptr<const XdmfAttributeCenter>
+ p(new XdmfAttributeCenter("Other"));
+ return p;
+}
+
+void
+XdmfAttributeCenter::InitTypes()
+{
+ mAttributeCenterDefinitions["GRID"] = Grid;
+ mAttributeCenterDefinitions["CELL"] = Cell;
+ mAttributeCenterDefinitions["FACE"] = Face;
+ mAttributeCenterDefinitions["EDGE"] = Edge;
+ mAttributeCenterDefinitions["NODE"] = Node;
+ mAttributeCenterDefinitions["OTHER"] = Other;
+}
+
+XdmfAttributeCenter::XdmfAttributeCenter(const std::string & name) :
+ mName(name)
+{
+}
+
+XdmfAttributeCenter::~XdmfAttributeCenter()
+{
+}
+
+shared_ptr<const XdmfAttributeCenter>
+XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+ std::map<std::string, std::string>::const_iterator center =
+ itemProperties.find("Center");
+ if(center == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Center' not found in itemProperties in "
+ "XdmfAttributeCenter::New");
+ }
+
+ const std::string & centerVal = ConvertToUpper(center->second);
+
+ std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()>::const_iterator returnType = mAttributeCenterDefinitions.find(centerVal);
+
+ if (returnType == mAttributeCenterDefinitions.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Center not of 'Grid','Cell','Face','Edge','Node',"
+ "'Other' in XdmfAttributeCenter::New");
+ }
+ else {
+ return (*(returnType->second))();
+ }
+
+ XdmfError::message(XdmfError::FATAL,
+ "Center not of 'Grid','Cell','Face','Edge','Node',"
+ "'Other' in XdmfAttributeCenter::New");
+
+ // unreachable
+ return shared_ptr<const XdmfAttributeCenter>();
+}
+
+void
+XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("Center", mName));
+}
+
+// C Wrappers
+
+int XdmfAttributeCenterGrid()
+{
+ return XDMF_ATTRIBUTE_CENTER_GRID;
+}
+
+int XdmfAttributeCenterCell()
+{
+ return XDMF_ATTRIBUTE_CENTER_CELL;
+}
+
+int XdmfAttributeCenterFace()
+{
+ return XDMF_ATTRIBUTE_CENTER_FACE;
+}
+
+int XdmfAttributeCenterEdge()
+{
+ return XDMF_ATTRIBUTE_CENTER_EDGE;
+}
+
+int XdmfAttributeCenterNode()
+{
+ return XDMF_ATTRIBUTE_CENTER_NODE;
+}
+
+int XdmfAttributeCenterOther()
+{
+ return XDMF_ATTRIBUTE_CENTER_OTHER;
+}
+
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAttributeCenter.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFATTRIBUTECENTER_HPP_
+#define XDMFATTRIBUTECENTER_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItemProperty.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Property describing where XdmfAttribute values are centered.
+ *
+ * XdmfAttributeCenter is a property used by XdmfAttribute to specify
+ * where its values are centered on an XdmfGrid. A specific
+ * XdmfAttributeCenter can be created by calling on of the static
+ * methods in the class, i.e. XdmfAttributeCenter::Cell().
+ * Xdmf supports the following attribute centers:
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setCenter
+ * @until //#setCenter
+ * @skipline //#getCenter
+ * @until //#getCenter
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setCenter
+ * @until #//setCenter
+ * @skipline #//getCenter
+ * @until #//getCenter
+ *
+ * Grid
+ * Cell
+ * Face
+ * Edge
+ * Node
+ */
+class XDMF_EXPORT XdmfAttributeCenter : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfAttributeCenter();
+
+ friend class XdmfAttribute;
+
+ // Supported Xdmf Attribute Centers
+ static shared_ptr<const XdmfAttributeCenter> Grid();
+ static shared_ptr<const XdmfAttributeCenter> Cell();
+ static shared_ptr<const XdmfAttributeCenter> Face();
+ static shared_ptr<const XdmfAttributeCenter> Edge();
+ static shared_ptr<const XdmfAttributeCenter> Node();
+ static shared_ptr<const XdmfAttributeCenter> Other();
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+
+protected:
+
+ /**
+ * Protected constructor for XdmfAttributeCenter. The constructor
+ * is protected because all attribute centers supported by Xdmf
+ * should be accessed through more specific static methods that
+ * construct XdmfAttributeCenters -
+ * i.e. XdmfAttributeCenter::Node().
+ *
+ * @param name The name of the XdmfAttributeCenter to construct.
+ */
+ XdmfAttributeCenter(const std::string & name);
+
+ static std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()> mAttributeCenterDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfAttributeCenter(const XdmfAttributeCenter &); // Not implemented.
+ void operator=(const XdmfAttributeCenter &); // Not implemented.
+
+ static shared_ptr<const XdmfAttributeCenter>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ std::string mName;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#define XDMF_ATTRIBUTE_CENTER_GRID 100
+#define XDMF_ATTRIBUTE_CENTER_CELL 101
+#define XDMF_ATTRIBUTE_CENTER_FACE 102
+#define XDMF_ATTRIBUTE_CENTER_EDGE 103
+#define XDMF_ATTRIBUTE_CENTER_NODE 104
+#define XDMF_ATTRIBUTE_CENTER_OTHER 105
+
+XDMF_EXPORT int XdmfAttributeCenterGrid();
+XDMF_EXPORT int XdmfAttributeCenterCell();
+XDMF_EXPORT int XdmfAttributeCenterFace();
+XDMF_EXPORT int XdmfAttributeCenterEdge();
+XDMF_EXPORT int XdmfAttributeCenterNode();
+XDMF_EXPORT int XdmfAttributeCenterOther();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFATTRIBUTECENTER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAttributeType.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfAttributeType.hpp"
+#include "XdmfError.hpp"
+
+std::map<std::string, shared_ptr<const XdmfAttributeType>(*)()> XdmfAttributeType::mAttributeDefinitions;
+
+// Supported XdmfAttributeTypes
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::NoAttributeType()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("None"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::Scalar()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("Scalar"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::Vector()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("Vector"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::Tensor()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("Tensor"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::Matrix()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("Matrix"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::Tensor6()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("Tensor6"));
+ return p;
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::GlobalId()
+{
+ static shared_ptr<const XdmfAttributeType>
+ p(new XdmfAttributeType("GlobalId"));
+ return p;
+}
+
+void
+XdmfAttributeType::InitTypes()
+{
+ mAttributeDefinitions["NONE"] = NoAttributeType;
+ mAttributeDefinitions["SCALAR"] = Scalar;
+ mAttributeDefinitions["VECTOR"] = Vector;
+ mAttributeDefinitions["TENSOR"] = Tensor;
+ mAttributeDefinitions["MATRIX"] = Matrix;
+ mAttributeDefinitions["TENSOR6"] = Tensor6;
+ mAttributeDefinitions["GLOBALID"] = GlobalId;
+}
+
+XdmfAttributeType::XdmfAttributeType(const std::string & name) :
+ mName(name)
+{
+}
+
+XdmfAttributeType::~XdmfAttributeType()
+{
+}
+
+shared_ptr<const XdmfAttributeType>
+XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("AttributeType");
+ }
+ if(type == itemProperties.end()) {
+ // to support old xdmf defaults, return Scalar()
+ return Scalar();
+ }
+
+
+ const std::string & typeVal = ConvertToUpper(type->second);
+
+ std::map<std::string, shared_ptr<const XdmfAttributeType>(*)()>::const_iterator returnType = mAttributeDefinitions.find(typeVal);
+
+ if (returnType == mAttributeDefinitions.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Type not of 'None','Scalar','Vector','Tensor', "
+ "'Matrix','Tensor6', or 'GlobalId' in "
+ "XdmfAttributeType::New");
+ }
+ else {
+ return (*(returnType->second))();
+ }
+
+ // unreachable
+ return shared_ptr<const XdmfAttributeType>();
+}
+
+void
+XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("Type", mName));
+}
+
+// C Wrappers
+
+int XdmfAttributeTypeScalar()
+{
+ return XDMF_ATTRIBUTE_TYPE_SCALAR;
+}
+
+int XdmfAttributeTypeVector()
+{
+ return XDMF_ATTRIBUTE_TYPE_VECTOR;
+}
+
+int XdmfAttributeTypeTensor()
+{
+ return XDMF_ATTRIBUTE_TYPE_TENSOR;
+}
+
+int XdmfAttributeTypeMatrix()
+{
+ return XDMF_ATTRIBUTE_TYPE_MATRIX;
+}
+
+int XdmfAttributeTypeTensor6()
+{
+ return XDMF_ATTRIBUTE_TYPE_TENSOR6;
+}
+
+int XdmfAttributeTypeGlobalId()
+{
+ return XDMF_ATTRIBUTE_TYPE_GLOBALID;
+}
+
+int XdmfAttributeTypeNoAttributeType()
+{
+ return XDMF_ATTRIBUTE_TYPE_NOTYPE;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfAttributeType.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFATTRIBUTETYPE_HPP_
+#define XDMFATTRIBUTETYPE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+
+#ifdef __cplusplus
+
+#include "XdmfItemProperty.hpp"
+
+/**
+ * @brief Property describing the type of values an XdmfAttribute
+ * contains.
+ *
+ * XdmfAttributeType is a property used by XdmfAttribute to specify
+ * what type of values the XdmfAttribute contains. A specific
+ * XdmfAttributeType can be created by calling one of the static
+ * methods in the class, i.e. XdmfAttributeType::Scalar().
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfAttribute.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setType
+ * @until //#setType
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleAttribute.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setType
+ * @until #//setType
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * Xdmf supports the following attribute types:
+ * NoAttributeType
+ * Scalar
+ * Vector
+ * Tensor
+ * Matrix
+ * Tensor6
+ * GlobalId
+ */
+class XDMF_EXPORT XdmfAttributeType : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfAttributeType();
+
+ friend class XdmfAttribute;
+
+ // Supported Xdmf Attribute Types
+ static shared_ptr<const XdmfAttributeType> NoAttributeType();
+ static shared_ptr<const XdmfAttributeType> Scalar();
+ static shared_ptr<const XdmfAttributeType> Vector();
+ static shared_ptr<const XdmfAttributeType> Tensor();
+ static shared_ptr<const XdmfAttributeType> Matrix();
+ static shared_ptr<const XdmfAttributeType> Tensor6();
+ static shared_ptr<const XdmfAttributeType> GlobalId();
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+protected:
+
+ /**
+ * Protected constructor for XdmfAttributeType. The constructor is
+ * protected because all attribute types supported by Xdmf should be
+ * accessed through more specific static methods that construct
+ * XdmfAttributeTypes - i.e. XdmfAttributeType::Scalar().
+ *
+ * @param name The name of the XdmfAttributeType to construct.
+ */
+ XdmfAttributeType(const std::string & name);
+
+ static std::map<std::string, shared_ptr<const XdmfAttributeType>(*)()> mAttributeDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfAttributeType(const XdmfAttributeType &); // Not implemented.
+ void operator=(const XdmfAttributeType &); // Not implemented.
+
+ static shared_ptr<const XdmfAttributeType>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ std::string mName;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#define XDMF_ATTRIBUTE_TYPE_SCALAR 200
+#define XDMF_ATTRIBUTE_TYPE_VECTOR 201
+#define XDMF_ATTRIBUTE_TYPE_TENSOR 202
+#define XDMF_ATTRIBUTE_TYPE_MATRIX 203
+#define XDMF_ATTRIBUTE_TYPE_TENSOR6 204
+#define XDMF_ATTRIBUTE_TYPE_GLOBALID 205
+#define XDMF_ATTRIBUTE_TYPE_NOTYPE 206
+
+XDMF_EXPORT int XdmfAttributeTypeScalar();
+XDMF_EXPORT int XdmfAttributeTypeVector();
+XDMF_EXPORT int XdmfAttributeTypeTensor();
+XDMF_EXPORT int XdmfAttributeTypeMatrix();
+XDMF_EXPORT int XdmfAttributeTypeTensor6();
+XDMF_EXPORT int XdmfAttributeTypeGlobalId();
+XDMF_EXPORT int XdmfAttributeTypeNoAttributeType();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFATTRIBUTETYPE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfConfig.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFCONFIG_HPP_
+#define XDMFCONFIG_HPP_
+
+#cmakedefine BUILD_SHARED
+#ifndef BUILD_SHARED
+# define XDMFSTATIC
+#endif
+
+#endif
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCurviliniearGrid.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <cmath>
+#include "XdmfArray.hpp"
+#include "XdmfCurvilinearGrid.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfTopologyType.hpp"
+#include "XdmfError.hpp"
+
+/**
+ * PIMPL
+ */
+class XdmfCurvilinearGrid::XdmfCurvilinearGridImpl : public XdmfGridImpl {
+
+public:
+
+ class XdmfTopologyCurvilinear : public XdmfTopology
+ {
+
+ public:
+
+ static shared_ptr<XdmfTopologyCurvilinear>
+ New(const XdmfCurvilinearGrid * const curvilinearGrid)
+ {
+ shared_ptr<XdmfTopologyCurvilinear>
+ p(new XdmfTopologyCurvilinear(curvilinearGrid));
+ return p;
+ }
+
+ bool isInitialized() const
+ {
+ return true;
+ }
+
+ unsigned int
+ getNumberElements() const
+ {
+ const shared_ptr<const XdmfArray> dimensions =
+ mCurvilinearGrid->getDimensions();
+ if(dimensions->getSize() == 0) {
+ return 0;
+ }
+ unsigned int toReturn = 1;
+ for(unsigned int i=0; i<dimensions->getSize(); ++i) {
+ toReturn *= (dimensions->getValue<unsigned int>(i) - 1);
+ }
+ return toReturn;
+ }
+
+ private:
+
+ XdmfTopologyCurvilinear(const XdmfCurvilinearGrid * const curvilinearGrid) :
+ mCurvilinearGrid(curvilinearGrid)
+ {
+ this->setType(XdmfTopologyTypeCurvilinear::New(curvilinearGrid));
+ }
+
+ const XdmfCurvilinearGrid * const mCurvilinearGrid;
+ };
+
+ class XdmfTopologyTypeCurvilinear : public XdmfTopologyType
+ {
+
+ public:
+
+ static shared_ptr<const XdmfTopologyTypeCurvilinear>
+ New(const XdmfCurvilinearGrid * const curvilinearGrid)
+ {
+ shared_ptr<const XdmfTopologyTypeCurvilinear>
+ p(new XdmfTopologyTypeCurvilinear(curvilinearGrid));
+ return p;
+ }
+
+ unsigned int
+ getEdgesPerElement() const
+ {
+ return calculateHypercubeNumElements(mCurvilinearGrid->getDimensions()->getSize(), 1);
+/*
+ const unsigned int dimensions =
+ mCurvilinearGrid->getDimensions()->getSize();
+ if (dimensions == 1) {
+ return 1;
+ }
+ if(dimensions == 2) {
+ return 4;
+ }
+ else if(dimensions >= 3) {
+ return 12;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Grid dimensions not 2 or 3 in "
+ "XdmfTopologyTypeCurvilinear::getEdgesPerElement");
+ }
+ return 0;
+*/
+ }
+
+ unsigned int
+ getFacesPerElement() const
+ {
+ return calculateHypercubeNumElements(mCurvilinearGrid->getDimensions()->getSize(), 2);
+/*
+ const unsigned int dimensions =
+ mCurvilinearGrid->getDimensions()->getSize();
+ if (dimensions == 1) {
+ return 0;
+ }
+ else if(dimensions == 2) {
+ return 1;
+ }
+ else if(dimensions == 3) {
+ return 6;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Grid dimensions not 2 or 3 in "
+ "XdmfTopologyTypeCurvilinear::getFacesPerElement");
+ }
+ return 0;
+*/
+ }
+
+ unsigned int
+ getNodesPerElement() const
+ {
+ return calculateHypercubeNumElements(mCurvilinearGrid->getDimensions()->getSize(), 0);
+ // 2^Dimensions
+ // e.g. 1D = 2 nodes per element and 2D = 4 nodes per element.
+// return (unsigned int)
+// std::pow(2, (double)mCurvilinearGrid->getDimensions()->getSize());
+ }
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const
+ {
+ shared_ptr<const XdmfArray> dimensions =
+ mCurvilinearGrid->getDimensions();
+ if(dimensions->getSize() == 3) {
+ collectedProperties["Type"] = "3DSMesh";
+ }
+ else if(dimensions->getSize() == 2) {
+ collectedProperties["Type"] = "2DSMesh";
+ }
+ else {
+ collectedProperties["Type"] = "SMesh";
+// XdmfError::message(XdmfError::FATAL,
+// "Grid dimensions not 2 or 3 in "
+// "XdmfTopologyTypeCurvilinear::getProperties");
+ }
+ collectedProperties["Dimensions"] = dimensions->getValuesString();
+ }
+
+ private:
+
+ XdmfTopologyTypeCurvilinear(const XdmfCurvilinearGrid * const curvilinearGrid) :
+ XdmfTopologyType(0,
+ 0,
+ std::vector<shared_ptr<const XdmfTopologyType> >(),
+ 0,
+ "foo",
+ XdmfTopologyType::Structured,
+ 0x1110),
+ mCurvilinearGrid(curvilinearGrid)
+ {
+ }
+
+ const XdmfCurvilinearGrid * const mCurvilinearGrid;
+
+ };
+
+ XdmfCurvilinearGridImpl(const shared_ptr<XdmfArray> numPoints) :
+ mDimensions(numPoints)
+ {
+ mGridType ="Curvilinear";
+ }
+
+ XdmfGridImpl * duplicate()
+ {
+ return new XdmfCurvilinearGridImpl(mDimensions);
+ }
+
+ shared_ptr<XdmfArray> mDimensions;
+};
+
+shared_ptr<XdmfCurvilinearGrid>
+XdmfCurvilinearGrid::New(const unsigned int xNumPoints,
+ const unsigned int yNumPoints)
+{
+ shared_ptr<XdmfArray> numPoints = XdmfArray::New();
+ numPoints->initialize<unsigned int>(2);
+ numPoints->insert(0, xNumPoints);
+ numPoints->insert(1, yNumPoints);
+ shared_ptr<XdmfCurvilinearGrid> p(new XdmfCurvilinearGrid(numPoints));
+ return p;
+}
+
+shared_ptr<XdmfCurvilinearGrid>
+XdmfCurvilinearGrid::New(const unsigned int xNumPoints,
+ const unsigned int yNumPoints,
+ const unsigned int zNumPoints)
+{
+ shared_ptr<XdmfArray> numPoints = XdmfArray::New();
+ numPoints->initialize<unsigned int>(3);
+ numPoints->insert(0, xNumPoints);
+ numPoints->insert(1, yNumPoints);
+ numPoints->insert(2, zNumPoints);
+ shared_ptr<XdmfCurvilinearGrid> p(new XdmfCurvilinearGrid(numPoints));
+ return p;
+}
+
+shared_ptr<XdmfCurvilinearGrid>
+XdmfCurvilinearGrid::New(const shared_ptr<XdmfArray> numPoints)
+{
+ shared_ptr<XdmfCurvilinearGrid> p(new XdmfCurvilinearGrid(numPoints));
+ return p;
+}
+
+XdmfCurvilinearGrid::XdmfCurvilinearGrid(const shared_ptr<XdmfArray> numPoints) :
+ XdmfGrid(XdmfGeometry::New(),
+ XdmfCurvilinearGridImpl::XdmfTopologyCurvilinear::New(this))
+{
+ mImpl = new XdmfCurvilinearGridImpl(numPoints);
+}
+
+XdmfCurvilinearGrid::XdmfCurvilinearGrid(XdmfCurvilinearGrid & refGrid) :
+ XdmfGrid(refGrid)
+{
+ mTopology = XdmfCurvilinearGridImpl::XdmfTopologyCurvilinear::New(this);
+}
+
+XdmfCurvilinearGrid::~XdmfCurvilinearGrid()
+{
+ if (mImpl) {
+ delete mImpl;
+ }
+ mImpl = NULL;
+}
+
+const std::string XdmfCurvilinearGrid::ItemTag = "Grid";
+
+void
+XdmfCurvilinearGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
+{
+ XdmfGrid::copyGrid(sourceGrid);
+ if (shared_ptr<XdmfCurvilinearGrid> classedGrid = shared_dynamic_cast<XdmfCurvilinearGrid>(sourceGrid))
+ {
+ // Copy stucture from read grid to this grid
+ this->setGeometry(classedGrid->getGeometry());
+ this->setDimensions(classedGrid->getDimensions());
+ }
+}
+
+shared_ptr<XdmfArray>
+XdmfCurvilinearGrid::getDimensions()
+{
+ return boost::const_pointer_cast<XdmfArray>
+ (static_cast<const XdmfCurvilinearGrid &>(*this).getDimensions());
+}
+
+shared_ptr<const XdmfArray>
+XdmfCurvilinearGrid::getDimensions() const
+{
+ return ((XdmfCurvilinearGridImpl *)mImpl)->mDimensions;
+}
+
+shared_ptr<XdmfGeometry>
+XdmfCurvilinearGrid::getGeometry()
+{
+ return boost::const_pointer_cast<XdmfGeometry>
+ (static_cast<const XdmfGrid &>(*this).getGeometry());
+}
+
+void
+XdmfCurvilinearGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfGrid::populateItem(itemProperties, childItems, reader);
+
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfCurvilinearGrid> curvilinearGrid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(*iter)) {
+ ((XdmfCurvilinearGridImpl *)mImpl)->mDimensions = curvilinearGrid->getDimensions();
+ }
+ }
+}
+
+void
+XdmfCurvilinearGrid::read()
+{
+ if (mGridController)
+ {
+ if (shared_ptr<XdmfCurvilinearGrid> grid = shared_dynamic_cast<XdmfCurvilinearGrid>(mGridController->read()))
+ {
+ // Copy stucture from read grid to this grid
+ copyGrid(grid);
+ }
+ else if (shared_dynamic_cast<XdmfGrid>(mGridController->read()))
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference");
+ }
+ }
+}
+
+void
+XdmfCurvilinearGrid::release()
+{
+ XdmfGrid::release();
+ this->setGeometry(shared_ptr<XdmfGeometry>());
+ this->setDimensions(shared_ptr<XdmfArray>());
+}
+
+void
+XdmfCurvilinearGrid::setDimensions(const shared_ptr<XdmfArray> dimensions)
+{
+ ((XdmfCurvilinearGridImpl *)mImpl)->mDimensions = dimensions;
+ this->setIsChanged(true);
+}
+
+void
+XdmfCurvilinearGrid::setGeometry(const shared_ptr<XdmfGeometry> geometry)
+{
+ mGeometry = geometry;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+XDMFCURVILINEARGRID * XdmfCurvilinearGridNew2D(unsigned int xNumPoints,
+ unsigned int yNumPoints)
+{
+ try
+ {
+ shared_ptr<XdmfCurvilinearGrid> generatedGrid = XdmfCurvilinearGrid::New(xNumPoints, yNumPoints);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfCurvilinearGrid> generatedGrid = XdmfCurvilinearGrid::New(xNumPoints, yNumPoints);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*generatedGrid.get()))));
+ }
+}
+
+XDMFCURVILINEARGRID * XdmfCurvilinearGridNew3D(unsigned int xNumPoints,
+ unsigned int yNumPoints,
+ unsigned int zNumPoints)
+{
+ try
+ {
+ shared_ptr<XdmfCurvilinearGrid> generatedGrid = XdmfCurvilinearGrid::New(xNumPoints, yNumPoints, zNumPoints);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfCurvilinearGrid> generatedGrid = XdmfCurvilinearGrid::New(xNumPoints, yNumPoints, zNumPoints);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*generatedGrid.get()))));
+ }
+}
+
+XDMFCURVILINEARGRID * XdmfCurvilinearGridNew(XDMFARRAY * numPoints, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ shared_ptr<XdmfArray> tempArray = shared_ptr<XdmfArray>((XdmfArray *)numPoints, XdmfNullDeleter());
+ shared_ptr<XdmfCurvilinearGrid> generatedGrid = XdmfCurvilinearGrid::New(tempArray);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfArray> tempArray = shared_ptr<XdmfArray>((XdmfArray *)numPoints, XdmfNullDeleter());
+ shared_ptr<XdmfCurvilinearGrid> generatedGrid = XdmfCurvilinearGrid::New(tempArray);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*generatedGrid.get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfCurvilinearGridGetDimensions(XDMFCURVILINEARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfCurvilinearGrid * gridPointer = dynamic_cast<XdmfCurvilinearGrid *>(classedPointer);
+ shared_ptr<XdmfArray> generatedArray = gridPointer->getDimensions();
+ return (XDMFARRAY *)((void *)generatedArray.get());
+ }
+ catch (...)
+ {
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfCurvilinearGrid * gridPointer = dynamic_cast<XdmfCurvilinearGrid *>(classedPointer);
+ shared_ptr<XdmfArray> generatedArray = gridPointer->getDimensions();
+ return (XDMFARRAY *)((void *)generatedArray.get());
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFGEOMETRY * XdmfCurvilinearGridGetGeometry(XDMFCURVILINEARGRID * grid)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfCurvilinearGrid * gridPointer = dynamic_cast<XdmfCurvilinearGrid *>(classedPointer);
+ shared_ptr<XdmfGeometry> generatedGeometry = gridPointer->getGeometry();
+ return (XDMFGEOMETRY *)((void *)generatedGeometry.get());
+}
+
+void XdmfCurvilinearGridSetDimensions(XDMFCURVILINEARGRID * grid, XDMFARRAY * dimensions, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfCurvilinearGrid * gridPointer = dynamic_cast<XdmfCurvilinearGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setDimensions(shared_ptr<XdmfArray>((XdmfArray *)dimensions));
+ }
+ else {
+ gridPointer->setDimensions(shared_ptr<XdmfArray>((XdmfArray *)dimensions, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfCurvilinearGridSetGeometry(XDMFCURVILINEARGRID * grid, XDMFGEOMETRY * geometry, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfCurvilinearGrid * gridPointer = dynamic_cast<XdmfCurvilinearGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setGeometry(shared_ptr<XdmfGeometry>((XdmfGeometry *)geometry));
+ }
+ else {
+ gridPointer->setGeometry(shared_ptr<XdmfGeometry>((XdmfGeometry *)geometry, XdmfNullDeleter()));
+ }
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfCurvilinearGrid, XDMFCURVILINEARGRID)
+XDMF_GRID_C_CHILD_WRAPPER(XdmfCurvilinearGrid, XDMFCURVILINEARGRID)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCurvilinearGrid.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFCURVILINEARGRID_HPP_
+#define XDMFCURVILINEARGRID_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfGrid.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+/**
+ * @brief A curvilinear (or structured) grid consisting of cells and
+ * points arranged on a regular lattice in space.
+ *
+ * XdmfCurvilinearGrid represents a mesh of cells and points arranged
+ * with regular topology and irregular geometry.
+ *
+ * In order to define a curvilinear grid, the dimensions of the grid
+ * must be supplied along with the coordinates of each point.
+ *
+ */
+class XDMF_EXPORT XdmfCurvilinearGrid : public XdmfGrid {
+
+public:
+
+ /**
+ * Create a new curvilinear grid (Two dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim2
+ * @until //#initializationdim2
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructor2
+ * @until #//constructor2
+ *
+ * @param xNumPoints The number of points in the x direction.
+ * @param yNumPoints The number of points in the y direction.
+ *
+ * @return Constructed curvilinear grid.
+ */
+ static shared_ptr<XdmfCurvilinearGrid>
+ New(const unsigned int xNumPoints,
+ const unsigned int yNumPoints);
+
+ /**
+ * Create a new curvilinear grid (Three dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim3
+ * @until //#initializationdim3
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructor3
+ * @until #//constructor3
+ *
+ * @param xNumPoints The number of points in the x direction.
+ * @param yNumPoints The number of points in the y direction.
+ * @param zNumPoints The number of points in the z direction.
+ *
+ * @return Constructed curvilinear grid.
+ */
+ static shared_ptr<XdmfCurvilinearGrid>
+ New(const unsigned int xNumPoints,
+ const unsigned int yNumPoints,
+ const unsigned int zNumPoints);
+
+ /**
+ * Create a new curvilinear grid (N dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructorvector
+ * @until #//constructorvector
+ *
+ * @param numPoints The number of points in each direction.
+ *
+ * @return Constructed curvilinear grid.
+ */
+ static shared_ptr<XdmfCurvilinearGrid>
+ New(const shared_ptr<XdmfArray> numPoints);
+
+ virtual ~XdmfCurvilinearGrid();
+
+ LOKI_DEFINE_VISITABLE(XdmfCurvilinearGrid, XdmfGrid)
+ static const std::string ItemTag;
+
+ /**
+ * Get the dimensions of the grid, the number of points in each
+ * direction.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim3
+ * @until //#initializationdim3
+ * @skipline //#setDimensions
+ * @until //#setDimensions
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructorvector
+ * @until #//constructorvector
+ * @skipline #//setDimensions
+ * @until #//setDimensions
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return XdmfArray containing dimensions of this grid.
+ */
+ shared_ptr<XdmfArray> getDimensions();
+
+ /**
+ * Get the dimensions of the grid, the number of points in each
+ * direction (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim3
+ * @until //#initializationdim3
+ * @skipline //#setDimensions
+ * @until //#setDimensions
+ * @skipline //#getDimensionsconst
+ * @until //#getDimensionsconst
+ *
+ * Python: Python doesn't have a constant version
+ *
+ * @return XdmfArray containing the dimensions of this grid.
+ */
+ shared_ptr<const XdmfArray> getDimensions() const;
+
+ /**
+ * Get the geometry associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim3
+ * @until //#initializationdim3
+ * @skipline //#setGeometry
+ * @until //#setGeometry
+ * @skipline //#getGeometry
+ * @until //#getGeometry
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructorvector
+ * @until #//constructorvector
+ * @skipline #//setGeometry
+ * @until #//setGeometry
+ * @skipline #//getGeometry
+ * @until #//getGeometry
+ *
+ * @return The geometry associated with this grid.
+ */
+ shared_ptr<XdmfGeometry> getGeometry();
+ using XdmfGrid::getGeometry;
+
+ virtual void read();
+
+ virtual void release();
+
+ /**
+ * Set the dimensions of the grid, the number of points in each
+ * direction.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim3
+ * @until //#initializationdim3
+ * @skipline //#setDimensions
+ * @until //#setDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructorvector
+ * @until #//constructorvector
+ * @skipline #//setDimensions
+ * @until #//setDimensions
+ *
+ * @param dimensions The dimension of the grid.
+ */
+ void setDimensions(const shared_ptr<XdmfArray> dimensions);
+
+ /**
+ * Set the geometry associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCurvilinearGrid.cpp
+ * @skipline //#initializationdim3
+ * @until //#initializationdim3
+ * @skipline //#setGeometry
+ * @until //#setGeometry
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCurvilinearGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//constructorvector
+ * @until #//constructorvector
+ * @skipline #//setGeometry
+ * @until #//setGeometry
+ *
+ * @param geometry An XdmfGeometry to associate with this grid.
+ */
+ void setGeometry(const shared_ptr<XdmfGeometry> geometry);
+
+ XdmfCurvilinearGrid(XdmfCurvilinearGrid &);
+
+protected:
+
+ XdmfCurvilinearGrid(const shared_ptr<XdmfArray> numPoints);
+
+ void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfCurvilinearGridImpl;
+ XdmfCurvilinearGrid(const XdmfCurvilinearGrid &); // Not implemented.
+ void operator=(const XdmfCurvilinearGrid &); // Not implemented.
+
+ void
+ copyGrid(shared_ptr<XdmfGrid> sourceGrid);
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFCURVILINEARGRID; // Simply as a typedef to ensure correct typing
+typedef struct XDMFCURVILINEARGRID XDMFCURVILINEARGRID;
+
+XDMF_EXPORT XDMFCURVILINEARGRID * XdmfCurvilinearGridNew2D(unsigned int xNumPoints,
+ unsigned int yNumPoints);
+
+XDMF_EXPORT XDMFCURVILINEARGRID * XdmfCurvilinearGridNew3D(unsigned int xNumPoints,
+ unsigned int yNumPoints,
+ unsigned int zNumPoints);
+
+XDMF_EXPORT XDMFCURVILINEARGRID * XdmfCurvilinearGridNew(XDMFARRAY * numPoints, int * status);
+
+XDMF_EXPORT XDMFARRAY * XdmfCurvilinearGridGetDimensions(XDMFCURVILINEARGRID * grid, int * status);
+
+XDMF_EXPORT XDMFGEOMETRY * XdmfCurvilinearGridGetGeometry(XDMFCURVILINEARGRID * grid);
+
+XDMF_EXPORT void XdmfCurvilinearGridSetDimensions(XDMFCURVILINEARGRID * grid, XDMFARRAY * dimensions, int passControl, int * status);
+
+XDMF_EXPORT void XdmfCurvilinearGridSetGeometry(XDMFCURVILINEARGRID * grid, XDMFGEOMETRY * geometry, int passControl);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfCurvilinearGrid, XDMFCURVILINEARGRID, XDMF)
+XDMF_GRID_C_CHILD_DECLARE(XdmfCurvilinearGrid, XDMFCURVILINEARGRID, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFCURVILINEARGRID_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfDomain.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfDomain.hpp"
+#include "XdmfCurvilinearGrid.hpp"
+#include "XdmfGraph.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfRectilinearGrid.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfUnstructuredGrid.hpp"
+
+#ifdef XDMF_BUILD_DSM
+ #include "XdmfDSMBuffer.hpp"
+ #include "XdmfDSMDriver.hpp"
+ #include "XdmfDSMDescription.hpp"
+#endif
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
+ XdmfGridCollection,
+ GridCollection,
+ Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
+ XdmfCurvilinearGrid,
+ CurvilinearGrid,
+ Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
+ XdmfGraph,
+ Graph,
+ Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
+ XdmfRectilinearGrid,
+ RectilinearGrid,
+ Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
+ XdmfRegularGrid,
+ RegularGrid,
+ Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
+ XdmfUnstructuredGrid,
+ UnstructuredGrid,
+ Name)
+
+shared_ptr<XdmfDomain>
+XdmfDomain::New()
+{
+ shared_ptr<XdmfDomain> p(new XdmfDomain());
+ return p;
+}
+
+XdmfDomain::XdmfDomain()
+{
+}
+
+XdmfDomain::XdmfDomain(XdmfDomain & refDomain) :
+ XdmfItem(refDomain),
+ mGridCollections(refDomain.mGridCollections),
+ mGraphs(refDomain.mGraphs),
+ mCurvilinearGrids(refDomain.mCurvilinearGrids),
+ mRectilinearGrids(refDomain.mRectilinearGrids),
+ mRegularGrids(refDomain.mRegularGrids),
+ mUnstructuredGrids(refDomain.mUnstructuredGrids)
+{
+}
+
+XdmfDomain::~XdmfDomain()
+{
+}
+
+const std::string XdmfDomain::ItemTag = "Domain";
+
+std::map<std::string, std::string>
+XdmfDomain::getItemProperties() const
+{
+ std::map<std::string, std::string> domainProperties;
+ return domainProperties;
+}
+
+std::string
+XdmfDomain::getItemTag() const
+{
+ return ItemTag;
+}
+
+void
+XdmfDomain::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfGridCollection> gridCollection =
+ shared_dynamic_cast<XdmfGridCollection>(*iter)) {
+ this->insert(gridCollection);
+ }
+ else if(shared_ptr<XdmfCurvilinearGrid> curvilinear_grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(*iter)) {
+ this->insert(curvilinear_grid);
+ }
+ else if(shared_ptr<XdmfGraph> graph =
+ shared_dynamic_cast<XdmfGraph>(*iter)) {
+ this->insert(graph);
+ }
+ else if(shared_ptr<XdmfRectilinearGrid> rect_grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
+ this->insert(rect_grid);
+ }
+ else if(shared_ptr<XdmfRegularGrid> regular_grid =
+ shared_dynamic_cast<XdmfRegularGrid>(*iter)) {
+ this->insert(regular_grid);
+ }
+ else if(shared_ptr<XdmfUnstructuredGrid> unstructured_grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(*iter)) {
+ this->insert(unstructured_grid);
+ }
+ }
+}
+
+void
+XdmfDomain::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+#ifdef XDMF_BUILD_DSM
+ // Traverse Data Descriptions before anything
+ XdmfDSMBuffer * dsmBuffer = (XdmfDSMBuffer *)xdmf_dsm_get_manager();
+
+ if (dsmBuffer)
+ {
+ shared_ptr<XdmfDSMDescription> dsmDescription;
+ dsmDescription = XdmfDSMDescription::New();
+ dsmDescription->setPortDescription(dsmBuffer->GetComm()->GetDsmPortName());
+
+ dsmDescription->accept(visitor);
+ }
+#endif
+
+ XdmfItem::traverse(visitor);
+ for (unsigned int i = 0; i < mGridCollections.size(); ++i)
+ {
+ mGridCollections[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mCurvilinearGrids.size(); ++i)
+ {
+ mCurvilinearGrids[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mGraphs.size(); ++i)
+ {
+ mGraphs[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mRectilinearGrids.size(); ++i)
+ {
+ mRectilinearGrids[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mRegularGrids.size(); ++i)
+ {
+ mRegularGrids[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mUnstructuredGrids.size(); ++i)
+ {
+ mUnstructuredGrids[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+XDMFDOMAIN * XdmfDomainNew()
+{
+ try
+ {
+ shared_ptr<XdmfDomain> generatedDomain = XdmfDomain::New();
+ return (XDMFDOMAIN *)((void *)((XdmfItem *)(new XdmfDomain(*generatedDomain.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfDomain> generatedDomain = XdmfDomain::New();
+ return (XDMFDOMAIN *)((void *)((XdmfItem *)(new XdmfDomain(*generatedDomain.get()))));
+ }
+}
+
+XDMFGRIDCOLLECTION * XdmfDomainGetGridCollection(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFGRIDCOLLECTION *)((void *)((XdmfItem *)(domainPointer->getGridCollection(index).get())));
+}
+
+XDMFGRIDCOLLECTION * XdmfDomainGetGridCollectionByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFGRIDCOLLECTION *)((void *)((XdmfItem *)(domainPointer->getGridCollection(Name).get())));
+}
+
+unsigned int XdmfDomainGetNumberGridCollections(XDMFDOMAIN * domain)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return domainPointer->getNumberGridCollections();
+}
+
+void XdmfDomainInsertGridCollection(XDMFDOMAIN * domain, XDMFGRIDCOLLECTION * GridCollection, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ if (passControl) {
+ domainPointer->insert(shared_ptr<XdmfGridCollection>((XdmfGridCollection *)GridCollection));
+ }
+ else {
+ domainPointer->insert(shared_ptr<XdmfGridCollection>((XdmfGridCollection *)GridCollection, XdmfNullDeleter()));
+ }
+}
+
+void XdmfDomainRemoveGridCollection(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeGridCollection(index);
+}
+
+void XdmfDomainRemoveGridCollectionByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeGridCollection(Name);
+}
+
+XDMFGRAPH * XdmfDomainGetGraph(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFGRAPH *)((void *)(domainPointer->getGraph(index).get()));
+}
+
+XDMFGRAPH * XdmfDomainGetGraphByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFGRAPH *)((void *)(domainPointer->getGraph(Name).get()));
+}
+
+unsigned int XdmfDomainGetNumberGraphs(XDMFDOMAIN * domain)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return domainPointer->getNumberGraphs();
+}
+
+void XdmfDomainInsertGraph(XDMFDOMAIN * domain, XDMFGRAPH * Graph, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ if (passControl) {
+ domainPointer->insert(shared_ptr<XdmfGraph>((XdmfGraph *)Graph));
+ }
+ else {
+ domainPointer->insert(shared_ptr<XdmfGraph>((XdmfGraph *)Graph, XdmfNullDeleter()));
+ }
+}
+
+void XdmfDomainRemoveGraph(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeGraph(index);
+}
+
+void XdmfDomainRemoveGraphByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeGraph(Name);
+}
+
+XDMFCURVILINEARGRID * XdmfDomainGetCurvilinearGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getCurvilinearGrid(index).get())));
+}
+
+XDMFCURVILINEARGRID * XdmfDomainGetCurvilinearGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getCurvilinearGrid(Name).get())));
+}
+
+unsigned int XdmfDomainGetNumberCurvilinearGrids(XDMFDOMAIN * domain)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return domainPointer->getNumberCurvilinearGrids();
+}
+
+void XdmfDomainInsertCurvilinearGrid(XDMFDOMAIN * domain, XDMFCURVILINEARGRID * CurvilinearGrid, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ if (passControl) {
+ domainPointer->insert(shared_ptr<XdmfCurvilinearGrid>((XdmfCurvilinearGrid *)CurvilinearGrid));
+ }
+ else {
+ domainPointer->insert(shared_ptr<XdmfCurvilinearGrid>((XdmfCurvilinearGrid *)CurvilinearGrid, XdmfNullDeleter()));
+ }
+}
+
+void XdmfDomainRemoveCurvilinearGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeCurvilinearGrid(index);
+}
+
+void XdmfDomainRemoveCurvilinearGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeCurvilinearGrid(Name);
+}
+
+XDMFRECTILINEARGRID * XdmfDomainGetRectilinearGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getRectilinearGrid(index).get())));
+}
+
+XDMFRECTILINEARGRID * XdmfDomainGetRectilinearGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getRectilinearGrid(Name).get())));
+}
+
+unsigned int XdmfDomainGetNumberRectilinearGrids(XDMFDOMAIN * domain)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return domainPointer->getNumberRectilinearGrids();
+}
+
+void XdmfDomainInsertRectilinearGrid(XDMFDOMAIN * domain, XDMFRECTILINEARGRID * RectilinearGrid, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ if (passControl) {
+ domainPointer->insert(shared_ptr<XdmfRectilinearGrid>((XdmfRectilinearGrid *)RectilinearGrid));
+ }
+ else {
+ domainPointer->insert(shared_ptr<XdmfRectilinearGrid>((XdmfRectilinearGrid *)RectilinearGrid, XdmfNullDeleter()));
+ }
+}
+
+void XdmfDomainRemoveRectilinearGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeRectilinearGrid(index);
+}
+
+void XdmfDomainRemoveRectilinearGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeRectilinearGrid(Name);
+}
+
+XDMFREGULARGRID * XdmfDomainGetRegularGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(domainPointer->getRegularGrid(index).get())));
+}
+
+XDMFREGULARGRID * XdmfDomainGetRegularGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(domainPointer->getRegularGrid(Name).get())));
+}
+
+unsigned int XdmfDomainGetNumberRegularGrids(XDMFDOMAIN * domain)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return domainPointer->getNumberRegularGrids();
+}
+
+void XdmfDomainInsertRegularGrid(XDMFDOMAIN * domain, XDMFREGULARGRID * RegularGrid, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ if (passControl) {
+ domainPointer->insert(shared_ptr<XdmfRegularGrid>((XdmfRegularGrid *)RegularGrid));
+ }
+ else {
+ domainPointer->insert(shared_ptr<XdmfRegularGrid>((XdmfRegularGrid *)RegularGrid, XdmfNullDeleter()));
+ }
+}
+
+void XdmfDomainRemoveRegularGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeRegularGrid(index);
+}
+
+void XdmfDomainRemoveRegularGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeRegularGrid(Name);
+}
+
+XDMFUNSTRUCTUREDGRID * XdmfDomainGetUnstructuredGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(domainPointer->getUnstructuredGrid(index).get())));
+}
+
+XDMFUNSTRUCTUREDGRID * XdmfDomainGetUnstructuredGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(domainPointer->getUnstructuredGrid(Name).get())));
+}
+
+unsigned int XdmfDomainGetNumberUnstructuredGrids(XDMFDOMAIN * domain)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ return domainPointer->getNumberUnstructuredGrids();
+}
+
+void XdmfDomainInsertUnstructuredGrid(XDMFDOMAIN * domain, XDMFUNSTRUCTUREDGRID * UnstructuredGrid, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ if (passControl) {
+ domainPointer->insert(shared_ptr<XdmfUnstructuredGrid>((XdmfUnstructuredGrid *)UnstructuredGrid));
+ }
+ else {
+ domainPointer->insert(shared_ptr<XdmfUnstructuredGrid>((XdmfUnstructuredGrid *)UnstructuredGrid, XdmfNullDeleter()));
+ }
+}
+
+void XdmfDomainRemoveUnstructuredGrid(XDMFDOMAIN * domain, unsigned int index)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeUnstructuredGrid(index);
+}
+
+void XdmfDomainRemoveUnstructuredGridByName(XDMFDOMAIN * domain, char * Name)
+{
+ XdmfItem * classedPointer = (XdmfItem *)domain;
+ XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
+ domainPointer->removeUnstructuredGrid(Name);
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfDomain, XDMFDOMAIN)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfDomain.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFDOMAIN_HPP_
+#define XDMFDOMAIN_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfCurvilinearGrid.hpp"
+#include "XdmfGraph.hpp"
+#include "XdmfRectilinearGrid.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfUnstructuredGrid.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfGridCollection;
+
+/**
+ * @brief The root XdmfItem that holds XdmfGrids.
+ *
+ * XdmfDomain is the top XdmfItem in an Xdmf structure. It can store
+ * a number of grids and provides methods to insert, retrieve, and
+ * remove these grids.
+ */
+class XDMF_EXPORT XdmfDomain : public virtual XdmfItem {
+
+public:
+
+ /**
+ * Create a new XdmfDomain.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfDomain.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleDomain.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfDomain.
+ */
+ static shared_ptr<XdmfDomain> New();
+
+ virtual ~XdmfDomain();
+
+ LOKI_DEFINE_VISITABLE(XdmfDomain, XdmfItem)
+ XDMF_CHILDREN(XdmfDomain, XdmfGridCollection, GridCollection, Name)
+ XDMF_CHILDREN(XdmfDomain, XdmfGraph, Graph, Name)
+ XDMF_CHILDREN(XdmfDomain, XdmfCurvilinearGrid, CurvilinearGrid, Name)
+ XDMF_CHILDREN(XdmfDomain, XdmfRectilinearGrid, RectilinearGrid, Name)
+ XDMF_CHILDREN(XdmfDomain, XdmfRegularGrid, RegularGrid, Name)
+ XDMF_CHILDREN(XdmfDomain, XdmfUnstructuredGrid, UnstructuredGrid, Name)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ virtual std::string getItemTag() const;
+
+ using XdmfItem::insert;
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfDomain(XdmfDomain &);
+
+protected:
+
+ XdmfDomain();
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfDomain(const XdmfDomain &); // Not implemented.
+ void operator=(const XdmfDomain &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFDOMAIN; // Simply as a typedef to ensure correct typing
+typedef struct XDMFDOMAIN XDMFDOMAIN;
+
+#ifndef XDMFGRIDCOLLECTIONCDEFINE
+#define XDMFGRIDCOLLECTIONCDEFINE
+struct XDMFGRIDCOLLECTION; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRIDCOLLECTION XDMFGRIDCOLLECTION;
+#endif
+
+XDMF_EXPORT XDMFDOMAIN * XdmfDomainNew();
+
+XDMF_EXPORT XDMFGRIDCOLLECTION * XdmfDomainGetGridCollection(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT XDMFGRIDCOLLECTION * XdmfDomainGetGridCollectionByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT unsigned int XdmfDomainGetNumberGridCollections(XDMFDOMAIN * domain);
+
+XDMF_EXPORT void XdmfDomainInsertGridCollection(XDMFDOMAIN * domain, XDMFGRIDCOLLECTION * GridCollection, int passControl);
+
+XDMF_EXPORT void XdmfDomainRemoveGridCollection(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT void XdmfDomainRemoveGridCollectionByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT XDMFGRAPH * XdmfDomainGetGraph(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT XDMFGRAPH * XdmfDomainGetGraphByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT unsigned int XdmfDomainGetNumberGraphs(XDMFDOMAIN * domain);
+
+XDMF_EXPORT void XdmfDomainInsertGraph(XDMFDOMAIN * domain, XDMFGRAPH * graph, int passControl);
+
+XDMF_EXPORT void XdmfDomainRemoveGraph(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT void XdmfDomainRemoveGraphByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT XDMFCURVILINEARGRID * XdmfDomainGetCurvilinearGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT XDMFCURVILINEARGRID * XdmfDomainGetCurvilinearGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT unsigned int XdmfDomainGetNumberCurvilinearGrids(XDMFDOMAIN * domain);
+
+XDMF_EXPORT void XdmfDomainInsertCurvilinearGrid(XDMFDOMAIN * domain, XDMFCURVILINEARGRID * CurvilinearGrid, int passControl);
+
+XDMF_EXPORT void XdmfDomainRemoveCurvilinearGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT void XdmfDomainRemoveCurvilinearGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT XDMFRECTILINEARGRID * XdmfDomainGetRectilinearGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT XDMFRECTILINEARGRID * XdmfDomainGetRectilinearGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT unsigned int XdmfDomainGetNumberRectilinearGrids(XDMFDOMAIN * domain);
+
+XDMF_EXPORT void XdmfDomainInsertRectilinearGrid(XDMFDOMAIN * domain, XDMFRECTILINEARGRID * RectilinearGrid, int passControl);
+
+XDMF_EXPORT void XdmfDomainRemoveRectilinearGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT void XdmfDomainRemoveRectilinearGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT XDMFREGULARGRID * XdmfDomainGetRegularGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT XDMFREGULARGRID * XdmfDomainGetRegularGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT unsigned int XdmfDomainGetNumberRegularGrids(XDMFDOMAIN * domain);
+
+XDMF_EXPORT void XdmfDomainInsertRegularGrid(XDMFDOMAIN * domain, XDMFREGULARGRID * RegularGrid, int passControl);
+
+XDMF_EXPORT void XdmfDomainRemoveRegularGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT void XdmfDomainRemoveRegularGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT XDMFUNSTRUCTUREDGRID * XdmfDomainGetUnstructuredGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT XDMFUNSTRUCTUREDGRID * XdmfDomainGetUnstructuredGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_EXPORT unsigned int XdmfDomainGetNumberUnstructuredGrids(XDMFDOMAIN * domain);
+
+XDMF_EXPORT void XdmfDomainInsertUnstructuredGrid(XDMFDOMAIN * domain, XDMFUNSTRUCTUREDGRID * UnstructuredGrid, int passControl);
+
+XDMF_EXPORT void XdmfDomainRemoveUnstructuredGrid(XDMFDOMAIN * domain, unsigned int index);
+
+XDMF_EXPORT void XdmfDomainRemoveUnstructuredGridByName(XDMFDOMAIN * domain, char * Name);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfDomain, XDMFDOMAIN, XDMF)
+
+#define XDMF_DOMAIN_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT XDMFGRIDCOLLECTION * ClassName##GetGridCollection(CClassName * domain, unsigned int index); \
+Level##_EXPORT XDMFGRIDCOLLECTION * ClassName##GetGridCollectionByName(CClassName * domain, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberGridCollections(CClassName * domain); \
+Level##_EXPORT void ClassName##InsertGridCollection(CClassName * domain, XDMFGRIDCOLLECTION * GridCollection, int passControl); \
+Level##_EXPORT void ClassName##RemoveGridCollection(CClassName * domain, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveGridCollectionByName(CClassName * domain, char * Name); \
+Level##_EXPORT XDMFGRAPH * ClassName##GetGraph(CClassName * domain, unsigned int index); \
+Level##_EXPORT XDMFGRAPH * ClassName##GetGraphByName(CClassName * domain, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberGraphs(CClassName * domain); \
+Level##_EXPORT void ClassName##InsertGraph(CClassName * domain, XDMFGRAPH * Graph, int passControl); \
+Level##_EXPORT void ClassName##RemoveGraph(CClassName * domain, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveGraphByName(CClassName * domain, char * Name); \
+Level##_EXPORT XDMFCURVILINEARGRID * ClassName##GetCurvilinearGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT XDMFCURVILINEARGRID * ClassName##GetCurvilinearGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberCurvilinearGrids(CClassName * domain); \
+Level##_EXPORT void ClassName##InsertCurvilinearGrid(CClassName * domain, XDMFCURVILINEARGRID * CurvilinearGrid, int passControl); \
+Level##_EXPORT void ClassName##RemoveCurvilinearGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveCurvilinearGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT XDMFRECTILINEARGRID * ClassName##GetRectilinearGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT XDMFRECTILINEARGRID * ClassName##GetRectilinearGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberRectilinearGrids(CClassName * domain); \
+Level##_EXPORT void ClassName##InsertRectilinearGrid(CClassName * domain, XDMFRECTILINEARGRID * RectilinearGrid, int passControl); \
+Level##_EXPORT void ClassName##RemoveRectilinearGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveRectilinearGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT XDMFREGULARGRID * ClassName##GetRegularGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT XDMFREGULARGRID * ClassName##GetRegularGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberRegularGrids(CClassName * domain); \
+Level##_EXPORT void ClassName##InsertRegularGrid(CClassName * domain, XDMFREGULARGRID * RegularGrid, int passControl); \
+Level##_EXPORT void ClassName##RemoveRegularGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveRegularGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT XDMFUNSTRUCTUREDGRID * ClassName##GetUnstructuredGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT XDMFUNSTRUCTUREDGRID * ClassName##GetUnstructuredGridByName(CClassName * domain, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberUnstructuredGrids(CClassName * domain); \
+Level##_EXPORT void ClassName##InsertUnstructuredGrid(CClassName * domain, XDMFUNSTRUCTUREDGRID * UnstructuredGrid, int passControl); \
+Level##_EXPORT void ClassName##RemoveUnstructuredGrid(CClassName * domain, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveUnstructuredGridByName(CClassName * domain, char * Name);
+
+
+#define XDMF_DOMAIN_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+XDMFGRIDCOLLECTION * ClassName##GetGridCollection(CClassName * domain, unsigned int index) \
+{ \
+ return XdmfDomainGetGridCollection((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+XDMFGRIDCOLLECTION * ClassName##GetGridCollectionByName(CClassName * domain, char * Name) \
+{ \
+ return XdmfDomainGetGridCollectionByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberGridCollections(CClassName * domain) \
+{ \
+ return XdmfDomainGetNumberGridCollections((XDMFDOMAIN *)((void *)domain)); \
+} \
+ \
+void ClassName##InsertGridCollection(CClassName * domain, XDMFGRIDCOLLECTION * GridCollection, int passControl) \
+{ \
+ XdmfDomainInsertGridCollection((XDMFDOMAIN *)((void *)domain), GridCollection, passControl); \
+} \
+ \
+void ClassName##RemoveGridCollection(CClassName * domain, unsigned int index) \
+{ \
+ XdmfDomainRemoveGridCollection((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+void ClassName##RemoveGridCollectionByName(CClassName * domain, char * Name) \
+{ \
+ XdmfDomainRemoveGridCollectionByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+XDMFGRAPH * ClassName##GetGraph(CClassName * domain, unsigned int index) \
+{ \
+ return XdmfDomainGetGraph((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+XDMFGRAPH * ClassName##GetGraphByName(CClassName * domain, char * Name) \
+{ \
+ return XdmfDomainGetGraphByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberGraphs(CClassName * domain) \
+{ \
+ return XdmfDomainGetNumberGraphs((XDMFDOMAIN *)((void *)domain)); \
+} \
+ \
+void ClassName##InsertGraph(CClassName * domain, XDMFGRAPH * Graph, int passControl) \
+{ \
+ XdmfDomainInsertGraph((XDMFDOMAIN *)((void *)domain), Graph, passControl); \
+} \
+ \
+void ClassName##RemoveGraph(CClassName * domain, unsigned int index) \
+{ \
+ XdmfDomainRemoveGraph((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+void ClassName##RemoveGraphByName(CClassName * domain, char * Name) \
+{ \
+ XdmfDomainRemoveGraphByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+XDMFCURVILINEARGRID * ClassName##GetCurvilinearGrid(CClassName * domain, unsigned int index) \
+{ \
+ return XdmfDomainGetCurvilinearGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+XDMFCURVILINEARGRID * ClassName##GetCurvilinearGridByName(CClassName * domain, char * Name) \
+{ \
+ return XdmfDomainGetCurvilinearGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberCurvilinearGrids(CClassName * domain) \
+{ \
+ return XdmfDomainGetNumberCurvilinearGrids((XDMFDOMAIN *)((void *)domain)); \
+} \
+ \
+void ClassName##InsertCurvilinearGrid(CClassName * domain, XDMFCURVILINEARGRID * CurvilinearGrid, int passControl) \
+{ \
+ XdmfDomainInsertCurvilinearGrid((XDMFDOMAIN *)((void *)domain), CurvilinearGrid, passControl); \
+} \
+ \
+void ClassName##RemoveCurvilinearGrid(CClassName * domain, unsigned int index) \
+{ \
+ XdmfDomainRemoveCurvilinearGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+void ClassName##RemoveCurvilinearGridByName(CClassName * domain, char * Name) \
+{ \
+ XdmfDomainRemoveCurvilinearGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+XDMFRECTILINEARGRID * ClassName##GetRectilinearGrid(CClassName * domain, unsigned int index) \
+{ \
+ return XdmfDomainGetRectilinearGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+XDMFRECTILINEARGRID * ClassName##GetRectilinearGridByName(CClassName * domain, char * Name) \
+{ \
+ return XdmfDomainGetRectilinearGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberRectilinearGrids(CClassName * domain) \
+{ \
+ return XdmfDomainGetNumberRectilinearGrids((XDMFDOMAIN *)((void *)domain)); \
+} \
+ \
+void ClassName##InsertRectilinearGrid(CClassName * domain, XDMFRECTILINEARGRID * RectilinearGrid, int passControl) \
+{ \
+ XdmfDomainInsertRectilinearGrid((XDMFDOMAIN *)((void *)domain), RectilinearGrid, passControl); \
+} \
+ \
+void ClassName##RemoveRectilinearGrid(CClassName * domain, unsigned int index) \
+{ \
+ XdmfDomainRemoveRectilinearGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+void ClassName##RemoveRectilinearGridByName(CClassName * domain, char * Name) \
+{ \
+ XdmfDomainRemoveRectilinearGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+XDMFREGULARGRID * ClassName##GetRegularGrid(CClassName * domain, unsigned int index) \
+{ \
+ return XdmfDomainGetRegularGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+XDMFREGULARGRID * ClassName##GetRegularGridByName(CClassName * domain, char * Name) \
+{ \
+ return XdmfDomainGetRegularGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberRegularGrids(CClassName * domain) \
+{ \
+ return XdmfDomainGetNumberRegularGrids((XDMFDOMAIN *)((void *)domain)); \
+} \
+ \
+void ClassName##InsertRegularGrid(CClassName * domain, XDMFREGULARGRID * RegularGrid, int passControl) \
+{ \
+ XdmfDomainInsertRegularGrid((XDMFDOMAIN *)((void *)domain), RegularGrid, passControl); \
+} \
+ \
+void ClassName##RemoveRegularGrid(CClassName * domain, unsigned int index) \
+{ \
+ XdmfDomainRemoveRegularGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+void ClassName##RemoveRegularGridByName(CClassName * domain, char * Name) \
+{ \
+ XdmfDomainRemoveRegularGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+XDMFUNSTRUCTUREDGRID * ClassName##GetUnstructuredGrid(CClassName * domain, unsigned int index) \
+{ \
+ return XdmfDomainGetUnstructuredGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+XDMFUNSTRUCTUREDGRID * ClassName##GetUnstructuredGridByName(CClassName * domain, char * Name) \
+{ \
+ return XdmfDomainGetUnstructuredGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberUnstructuredGrids(CClassName * domain) \
+{ \
+ return XdmfDomainGetNumberUnstructuredGrids((XDMFDOMAIN *)((void *)domain)); \
+} \
+ \
+void ClassName##InsertUnstructuredGrid(CClassName * domain, XDMFUNSTRUCTUREDGRID * UnstructuredGrid, int passControl) \
+{ \
+ XdmfDomainInsertUnstructuredGrid((XDMFDOMAIN *)((void *)domain), UnstructuredGrid, passControl); \
+} \
+ \
+void ClassName##RemoveUnstructuredGrid(CClassName * domain, unsigned int index) \
+{ \
+ XdmfDomainRemoveUnstructuredGrid((XDMFDOMAIN *)((void *)domain), index); \
+} \
+ \
+void ClassName##RemoveUnstructuredGridByName(CClassName * domain, char * Name) \
+{ \
+ XdmfDomainRemoveUnstructuredGridByName((XDMFDOMAIN *)((void *)domain), Name); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFDOMAIN_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGeometry.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfGeometry.hpp"
+#include "XdmfGeometryType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfFunction.hpp"
+#include <boost/tokenizer.hpp>
+
+#include <sstream>
+
+shared_ptr<XdmfGeometry> XdmfGeometry::New()
+{
+ shared_ptr<XdmfGeometry> p(new XdmfGeometry());
+ return p;
+}
+
+XdmfGeometry::XdmfGeometry() :
+ XdmfArray(),
+ mNumberPoints(0),
+ mType(XdmfGeometryType::NoGeometryType())
+{
+}
+
+XdmfGeometry::XdmfGeometry(XdmfGeometry & refGeometry) :
+ XdmfArray(refGeometry),
+ mType(refGeometry.mType),
+ mOrigin(refGeometry.mOrigin)
+{
+}
+
+XdmfGeometry::~XdmfGeometry()
+{
+}
+
+const std::string XdmfGeometry::ItemTag = "Geometry";
+
+std::map<std::string, std::string>
+XdmfGeometry::getItemProperties() const
+{
+ std::map<std::string, std::string> geometryProperties;
+ mType->getProperties(geometryProperties);
+ std::stringstream originstream;
+ for (unsigned int i = 0; i < mOrigin.size(); ++i) {
+ originstream << mOrigin[i];
+ if (i + 1 < mOrigin.size()) {
+ originstream << " ";
+ }
+ }
+ geometryProperties["Origin"] = originstream.str();
+ return geometryProperties;
+}
+
+std::string
+XdmfGeometry::getItemTag() const
+{
+ return ItemTag;
+}
+
+unsigned int
+XdmfGeometry::getNumberPoints() const
+{
+ if(mType->getDimensions() == 0) {
+ return 0;
+ }
+ else {
+ return this->getSize() / mType->getDimensions();
+ }
+}
+
+std::vector<double>
+XdmfGeometry::getOrigin() const
+{
+ std::vector<double> returnVector(mOrigin);
+ return returnVector;
+}
+
+shared_ptr<const XdmfGeometryType>
+XdmfGeometry::getType() const
+{
+ return mType;
+}
+
+void
+XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("GeometryType");
+ }
+
+ if (type != itemProperties.end()) {
+ if(type->second.compare("X_Y_Z") == 0) {
+ mType = XdmfGeometryType::XYZ();
+
+ // Building Function equivalent
+ std::vector<std::string> dimensionIDVector;
+ dimensionIDVector.push_back("X");
+ dimensionIDVector.push_back("Y");
+ dimensionIDVector.push_back("Z");
+
+ std::map<std::string, shared_ptr<XdmfArray> > dimensionMap;
+
+ unsigned int dimensionIDIndex = 0;
+
+ // Find X, Y, and Z Arrays
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end() && dimensionIDIndex < dimensionIDVector.size();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ dimensionMap[dimensionIDVector[dimensionIDIndex]] = array;
+ dimensionIDIndex++;
+ }
+ }
+
+ shared_ptr<XdmfFunction> geoFunction = XdmfFunction::New("X#Y#Z", dimensionMap);
+
+ this->setReference(geoFunction);
+ this->setReadMode(XdmfArray::Reference);
+ }
+ else if(type->second.compare("X_Y") == 0) {
+ mType = XdmfGeometryType::XY();
+
+ // Building Function equivalent
+ std::vector<std::string> dimensionIDVector;
+ dimensionIDVector.push_back("X");
+ dimensionIDVector.push_back("Y");
+
+ std::map<std::string, shared_ptr<XdmfArray> > dimensionMap;
+
+ unsigned int dimensionIDIndex = 0;
+
+ // Find X, Y, and Z Arrays
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end() && dimensionIDIndex < dimensionIDVector.size();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ dimensionMap[dimensionIDVector[dimensionIDIndex]] = array;
+ dimensionIDIndex++;
+ }
+ }
+
+ shared_ptr<XdmfFunction> geoFunction = XdmfFunction::New("X#Y", dimensionMap);
+
+ this->setReference(geoFunction);
+ this->setReadMode(XdmfArray::Reference);
+ }
+ else {
+ mType = XdmfGeometryType::New(itemProperties);
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ this->swap(array);
+ if (array->getReference()) {
+ this->setReference(array->getReference());
+ this->setReadMode(XdmfArray::Reference);
+ }
+ break;
+ }
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Neither 'Type' nor 'GeometryType' in itemProperties "
+ "in XdmfGeometry::populateItem");
+ }
+
+ std::map<std::string, std::string>::const_iterator origin =
+ itemProperties.find("Origin");
+ if (origin != itemProperties.end()) {
+ boost::tokenizer<> tokens(origin->second);
+ for(boost::tokenizer<>::const_iterator iter = tokens.begin();
+ iter != tokens.end();
+ ++iter) {
+ mOrigin.push_back(atof((*iter).c_str()));
+ }
+ }
+}
+
+void
+XdmfGeometry::setOrigin(double newX, double newY, double newZ)
+{
+ mOrigin.clear();
+ mOrigin.push_back(newX);
+ mOrigin.push_back(newY);
+ mOrigin.push_back(newZ);
+ this->setIsChanged(true);
+}
+
+void
+XdmfGeometry::setOrigin(std::vector<double> newOrigin)
+{
+ mOrigin.clear();
+ for (unsigned int i = 0; i < newOrigin.size(); ++i) {
+ mOrigin.push_back(newOrigin[i]);
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfGeometry::setType(const shared_ptr<const XdmfGeometryType> type)
+{
+ mType = type;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+XDMFGEOMETRY * XdmfGeometryNew()
+{
+ try
+ {
+ shared_ptr<XdmfGeometry> generatedGeometry = XdmfGeometry::New();
+ return (XDMFGEOMETRY *)((void *)(new XdmfGeometry(*generatedGeometry.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfGeometry> generatedGeometry = XdmfGeometry::New();
+ return (XDMFGEOMETRY *)((void *)(new XdmfGeometry(*generatedGeometry.get())));
+ }
+}
+
+unsigned int XdmfGeometryGetNumberPoints(XDMFGEOMETRY * geometry)
+{
+ return ((XdmfGeometry *) geometry)->getNumberPoints();
+}
+
+double *
+XdmfGeometryGetOrigin(XDMFGEOMETRY * geometry)
+{
+ try
+ {
+ std::vector<double> tempVector = ((XdmfGeometry *)(geometry))->getOrigin();
+ unsigned int returnSize = tempVector.size();
+ double * returnArray = new double[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<double> tempVector = ((XdmfGeometry *)(geometry))->getOrigin();
+ unsigned int returnSize = tempVector.size();
+ double * returnArray = new double[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+int
+XdmfGeometryGetOriginSize(XDMFGEOMETRY * geometry)
+{
+ return ((XdmfGeometry *) geometry)->getOrigin().size();
+}
+
+int XdmfGeometryGetType(XDMFGEOMETRY * geometry)
+{
+ if (((XdmfGeometry *) geometry)->getType() == XdmfGeometryType::NoGeometryType()) {
+ return XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE;
+ }
+ else if (((XdmfGeometry *) geometry)->getType() == XdmfGeometryType::XYZ()) {
+ return XDMF_GEOMETRY_TYPE_XYZ;
+ }
+ else if (((XdmfGeometry *) geometry)->getType() == XdmfGeometryType::XY()) {
+ return XDMF_GEOMETRY_TYPE_XY;
+ }
+ else if (((XdmfGeometry *) geometry)->getType() == XdmfGeometryType::Polar()) {
+ return XDMF_GEOMETRY_TYPE_POLAR;
+ }
+ else if (((XdmfGeometry *) geometry)->getType() == XdmfGeometryType::Spherical()) {
+ return XDMF_GEOMETRY_TYPE_SPHERICAL;
+ }
+ else {
+ return -1;
+ }
+}
+
+void
+XdmfGeometrySetOrigin(XDMFGEOMETRY * geometry, double newX, double newY, double newZ)
+{
+ ((XdmfGeometry *) geometry)->setOrigin(newX, newY, newZ);
+}
+
+void
+XdmfGeometrySetOriginArray(XDMFGEOMETRY * geometry, double * originVals, unsigned int numDims)
+{
+ std::vector<double> originVector;
+ for (unsigned int i = 0; i < numDims; ++i)
+ {
+ originVector.push_back(originVals[i]);
+ }
+ ((XdmfGeometry *) geometry)->setOrigin(originVector);
+}
+
+void XdmfGeometrySetType(XDMFGEOMETRY * geometry, int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (type) {
+ case XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE:
+ ((XdmfGeometry *) geometry)->setType(XdmfGeometryType::NoGeometryType());
+ break;
+ case XDMF_GEOMETRY_TYPE_XYZ:
+ ((XdmfGeometry *) geometry)->setType(XdmfGeometryType::XYZ());
+ break;
+ case XDMF_GEOMETRY_TYPE_XY:
+ ((XdmfGeometry *) geometry)->setType(XdmfGeometryType::XY());
+ break;
+ case XDMF_GEOMETRY_TYPE_POLAR:
+ ((XdmfGeometry *) geometry)->setType(XdmfGeometryType::Polar());
+ break;
+ case XDMF_GEOMETRY_TYPE_SPHERICAL:
+ ((XdmfGeometry *) geometry)->setType(XdmfGeometryType::Spherical());
+ break;
+ default:
+ {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Geometry Type: Code " << type;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfGeometry, XDMFGEOMETRY)
+XDMF_ARRAY_C_CHILD_WRAPPER(XdmfGeometry, XDMFGEOMETRY)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGeometry.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGEOMETRY_HPP_
+#define XDMFGEOMETRY_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfGeometryType.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Handles the coordinate positions of points in an XdmfGrid.
+ *
+ * XdmfGeometry is a required part of an XdmfGrid. It stores the
+ * coordinate locations of all points contained in an
+ * XdmfGrid. XdmfGeometry contains an XdmfGeometryType property which
+ * should be set that specifies the types of coordinate values stored.
+ */
+class XDMF_EXPORT XdmfGeometry : public XdmfArray {
+
+public:
+
+ /**
+ * Create a new XdmfGeometry.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometry.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometry.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfGeometry.
+ */
+ static shared_ptr<XdmfGeometry> New();
+
+ virtual ~XdmfGeometry();
+
+ LOKI_DEFINE_VISITABLE(XdmfGeometry, XdmfArray)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the number of points stored in this geometry.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometry.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getNumberPoints
+ * @until //#getNumberPoints
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometry.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getNumberPoints
+ * @until #//getNumberPoints
+ */
+ virtual unsigned int getNumberPoints() const;
+
+ /**
+ * Gets the origin of the geometry. This value defaults to (0, 0, 0)
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometry.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getOrigin
+ * @until //#getOrigin
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometry.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getOrigin
+ * @until #//getOrigin
+ *
+ * @return A vector containing the current location
+ * of the origin of this geometry
+ */
+ std::vector<double> getOrigin() const;
+
+ /**
+ * Get the XdmfGeometryType associated with this geometry.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometry.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometry.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * @return XdmfGeometryType of this geometry.
+ */
+ shared_ptr<const XdmfGeometryType> getType() const;
+
+ /**
+ * Sets the origin of the geometry.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometry.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setOrigin
+ * @until //#setOrigin
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometry.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setOrigin
+ * @until #//setOrigin
+ *
+ * @param newX The new X value of the origin.
+ * @param newY The new Y value of the origin.
+ * @param newZ The new Z value of the origin.
+ */
+ void setOrigin(double newX, double newY, double newZ = 0.0);
+
+ void setOrigin(std::vector<double> newOrigin);
+
+ /**
+ * Set the XdmfGeometryType associated with this geometry.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometry.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setType
+ * @until //#setType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometry.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setType
+ * @until #//setType
+ *
+ * @param type The XdmfGeometryType to set.
+ */
+ void setType(const shared_ptr<const XdmfGeometryType> type);
+
+ XdmfGeometry(XdmfGeometry &);
+
+protected:
+
+ XdmfGeometry();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfGeometry(const XdmfGeometry &); // Not implemented.
+ void operator=(const XdmfGeometry &); // Not implemented.
+
+ int mNumberPoints;
+ shared_ptr<const XdmfGeometryType> mType;
+
+ std::vector<double> mOrigin;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFGEOMETRY; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGEOMETRY XDMFGEOMETRY;
+
+XDMF_EXPORT XDMFGEOMETRY * XdmfGeometryNew();
+
+XDMF_EXPORT unsigned int XdmfGeometryGetNumberPoints(XDMFGEOMETRY * geometry);
+
+XDMF_EXPORT double * XdmfGeometryGetOrigin(XDMFGEOMETRY * geometry);
+
+XDMF_EXPORT int XdmfGeometryGetOriginSize(XDMFGEOMETRY * geometry);
+
+XDMF_EXPORT int XdmfGeometryGetType(XDMFGEOMETRY * geometry);
+
+XDMF_EXPORT void XdmfGeometrySetOrigin(XDMFGEOMETRY * geometry, double newX, double newY, double newZ);
+
+XDMF_EXPORT void XdmfGeometrySetOriginArray(XDMFGEOMETRY * geometry, double * originVals, unsigned int numDims);
+
+XDMF_EXPORT void XdmfGeometrySetType(XDMFGEOMETRY * geometry, int type, int * status);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfGeometry, XDMFGEOMETRY, XDMF)
+XDMF_ARRAY_C_CHILD_DECLARE(XdmfGeometry, XDMFGEOMETRY, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFGEOMETRY_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGeometryType.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfGeometryType.hpp"
+#include "XdmfError.hpp"
+#include "string.h"
+
+#include <sstream>
+
+std::map<std::string, shared_ptr<const XdmfGeometryType>(*)()> XdmfGeometryType::mGeometryDefinitions;
+
+// Supported XdmfGeometryTypes
+shared_ptr<const XdmfGeometryType>
+XdmfGeometryType::NoGeometryType()
+{
+ static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("None", 0));
+ return p;
+}
+
+shared_ptr<const XdmfGeometryType>
+XdmfGeometryType::XYZ()
+{
+ static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("XYZ", 3));
+ return p;
+}
+
+shared_ptr<const XdmfGeometryType>
+XdmfGeometryType::XY()
+{
+ static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("XY", 2));
+ return p;
+}
+
+shared_ptr<const XdmfGeometryType>
+XdmfGeometryType::Polar()
+{
+ static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("Polar", 2));
+ return p;
+}
+
+shared_ptr<const XdmfGeometryType>
+XdmfGeometryType::Spherical()
+{
+ static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("Spherical", 3));
+ return p;
+}
+
+void
+XdmfGeometryType::InitTypes()
+{
+ mGeometryDefinitions["NONE"] = NoGeometryType;
+ mGeometryDefinitions["XYZ"] = XYZ;
+ mGeometryDefinitions["XY"] = XY;
+ mGeometryDefinitions["POLAR"] = Polar;
+ mGeometryDefinitions["SPHERICAL"] = Spherical;
+}
+
+XdmfGeometryType::XdmfGeometryType(const std::string& name,
+ const int& dimensions) :
+ mDimensions(dimensions),
+ mName(name)
+{
+}
+
+XdmfGeometryType::~XdmfGeometryType()
+{
+}
+
+shared_ptr<const XdmfGeometryType>
+XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("GeometryType");
+ }
+ if(type == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Neither 'Type' nor 'GeometryType' in itemProperties "
+ "in XdmfGeometryType::New");
+ }
+
+ const std::string & typeVal = ConvertToUpper(type->second);
+
+ std::map<std::string, shared_ptr<const XdmfGeometryType>(*)()>::const_iterator returnType
+ = mGeometryDefinitions.find(typeVal);
+
+ if (returnType == mGeometryDefinitions.end()) {
+ XdmfError::message(XdmfError::FATAL, "Type "
+ + typeVal + " not Supported "
+ "in XdmfGeometryType::New");
+ }
+ else {
+ return (*(returnType->second))();
+ }
+
+ return shared_ptr<const XdmfGeometryType>();
+}
+
+unsigned int
+XdmfGeometryType::getDimensions() const
+{
+ return mDimensions;
+}
+
+std::string
+XdmfGeometryType::getName() const
+{
+ return mName;
+}
+
+void
+XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("Type", mName));
+}
+
+// C Wrappers
+
+int XdmfGeometryTypeNoGeometryType()
+{
+ return XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE;
+}
+
+int XdmfGeometryTypeXYZ()
+{
+ return XDMF_GEOMETRY_TYPE_XYZ;
+}
+
+int XdmfGeometryTypeXY()
+{
+ return XDMF_GEOMETRY_TYPE_XY;
+}
+
+int XdmfGeometryTypePolar()
+{
+ return XDMF_GEOMETRY_TYPE_POLAR;
+}
+
+int XdmfGeometryTypeSpherical()
+{
+ return XDMF_GEOMETRY_TYPE_SPHERICAL;
+}
+
+unsigned int XdmfGeometryTypeGetDimensions(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (type) {
+ case XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE:
+ return XdmfGeometryType::NoGeometryType()->getDimensions();
+ break;
+ case XDMF_GEOMETRY_TYPE_XYZ:
+ return XdmfGeometryType::XYZ()->getDimensions();
+ break;
+ case XDMF_GEOMETRY_TYPE_XY:
+ return XdmfGeometryType::XY()->getDimensions();
+ break;
+ case XDMF_GEOMETRY_TYPE_POLAR:
+ return XdmfGeometryType::Polar()->getDimensions();
+ break;
+ case XDMF_GEOMETRY_TYPE_SPHERICAL:
+ return XdmfGeometryType::Spherical()->getDimensions();
+ break;
+ default:
+ try {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Geometry Type: Code " << type;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ catch (XdmfError & e) {
+ throw e;
+ }
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+char * XdmfGeometryTypeGetName(int type)
+{
+ switch (type) {
+ case XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE:
+ {
+ char * returnPointer = strdup(XdmfGeometryType::NoGeometryType()->getName().c_str());
+ return returnPointer;
+ break;
+ }
+ case XDMF_GEOMETRY_TYPE_XYZ:
+ {
+ char * returnPointer = strdup(XdmfGeometryType::XYZ()->getName().c_str());
+ return returnPointer;
+ break;
+ }
+ case XDMF_GEOMETRY_TYPE_XY:
+ {
+ char * returnPointer = strdup(XdmfGeometryType::XY()->getName().c_str());
+ return returnPointer;
+ break;
+ }
+ case XDMF_GEOMETRY_TYPE_POLAR:
+ {
+ char * returnPointer = strdup(XdmfGeometryType::Polar()->getName().c_str());
+ return returnPointer;
+ break;
+ }
+ case XDMF_GEOMETRY_TYPE_SPHERICAL:
+ {
+ char * returnPointer = strdup(XdmfGeometryType::Spherical()->getName().c_str());
+ return returnPointer;
+ break;
+ }
+ default:
+ {
+ char * returnPointer = NULL;
+ return returnPointer;
+ break;
+ }
+ }
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGeometryType.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGEOMETRYTYPE_HPP_
+#define XDMFGEOMETRYTYPE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include "XdmfItemProperty.hpp"
+#include <map>
+
+/**
+ * @brief Property describing the types of coordinate values stored in
+ * an XdmfGeometry.
+ *
+ * XdmfGeometryType is a property used by XdmfGeometry to specify the
+ * type of coordinate values stored in the XdmfGeometry. A specific
+ * XdmfGeometryType can be created by calling one of the static
+ * methods in the class, i.e. XdmfAttributeType::XYZ().
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometryType.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometryType.py
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * Xdmf supports the following geometry types:
+ * NoGeometryType
+ * XYZ
+ * XY
+ * Polar
+ * Spherical
+ *
+ * The Polar and Spherical types consist of a series of coordinates.
+ * These coordinates are in order of: radius, polar, azimuthal.
+ * In accordance with the ISO standard.
+ *
+ */
+class XDMF_EXPORT XdmfGeometryType : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfGeometryType();
+
+ friend class XdmfGeometry;
+
+ // Supported Xdmf Geometry Types
+ static shared_ptr<const XdmfGeometryType> NoGeometryType();
+ static shared_ptr<const XdmfGeometryType> XYZ();
+ static shared_ptr<const XdmfGeometryType> XY();
+ static shared_ptr<const XdmfGeometryType> Polar();
+ static shared_ptr<const XdmfGeometryType> Spherical();
+
+ /**
+ * Get the dimensions of this geometry type - i.e. XYZ = 3.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometryType.cpp
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometryType.py
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return An int containing number of dimensions.
+ */
+ virtual unsigned int getDimensions() const;
+
+ /**
+ * Get the name of this geometry type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGeometryType.cpp
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGeometryType.py
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return The name of this geometry type.
+ */
+ std::string getName() const;
+
+ virtual void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+protected:
+
+ /**
+ * Protected constructor for XdmfGeometryType. The constructor is
+ * protected because all geometry types supported by Xdmf should be
+ * accessed through more specific static methods that construct
+ * XdmfGeometryTypes - i.e. XdmfGeometryType::XYZ().
+ *
+ * @param name a std::string containing the name of the geometry type..
+ * @param dimensions an int containing the dimensions of the geometry type.
+ */
+ XdmfGeometryType(const std::string & name, const int & dimensions);
+
+ static std::map<std::string, shared_ptr<const XdmfGeometryType>(*)()> mGeometryDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfGeometryType(const XdmfGeometryType &); // Not implemented.
+ void operator=(const XdmfGeometryType &); // Not implemented.
+
+ static shared_ptr<const XdmfGeometryType>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ unsigned int mDimensions;
+ std::string mName;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#define XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE 300
+#define XDMF_GEOMETRY_TYPE_XYZ 301
+#define XDMF_GEOMETRY_TYPE_XY 302
+#define XDMF_GEOMETRY_TYPE_POLAR 303
+#define XDMF_GEOMETRY_TYPE_SPHERICAL 304
+
+XDMF_EXPORT int XdmfGeometryTypeNoGeometryType();
+XDMF_EXPORT int XdmfGeometryTypeXYZ();
+XDMF_EXPORT int XdmfGeometryTypeXY();
+XDMF_EXPORT int XdmfGeometryTypePolar();
+XDMF_EXPORT int XdmfGeometryTypeSpherical();
+
+XDMF_EXPORT unsigned int XdmfGeometryTypeGetDimensions(int type, int * status);
+
+XDMF_EXPORT char * XdmfGeometryTypeGetName(int type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFGEOMETRYTYPE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGraph.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfAttribute.hpp"
+#include "XdmfGraph.hpp"
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfGraph, XdmfAttribute, Attribute, Name)
+
+shared_ptr<XdmfGraph>
+XdmfGraph::New(const unsigned int numberNodes)
+{
+ shared_ptr<XdmfGraph> p(new XdmfGraph(numberNodes));
+ return p;
+}
+
+XdmfGraph::XdmfGraph(const unsigned int numberNodes) :
+ XdmfSparseMatrix(numberNodes,
+ numberNodes),
+ mTime(shared_ptr<XdmfTime>())
+{
+}
+
+XdmfGraph::XdmfGraph(XdmfGraph & refGraph) :
+ XdmfSparseMatrix(refGraph),
+ mAttributes(refGraph.mAttributes),
+ mTime(refGraph.mTime)
+{
+}
+
+XdmfGraph::~XdmfGraph()
+{
+}
+
+const std::string XdmfGraph::ItemTag = "Graph";
+
+std::string
+XdmfGraph::getItemTag() const
+{
+ return ItemTag;
+}
+
+shared_ptr<XdmfTime>
+XdmfGraph::getTime()
+{
+ return boost::const_pointer_cast<XdmfTime>
+ (static_cast<const XdmfGraph &>(*this).getTime());
+}
+
+shared_ptr<const XdmfTime>
+XdmfGraph::getTime() const
+{
+ return mTime;
+}
+
+unsigned int
+XdmfGraph::getNumberNodes() const
+{
+ // The number of nodes is equal to the number of rows or columns. Either will work.
+ return this->getNumberRows();
+}
+
+void
+XdmfGraph::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfSparseMatrix::populateItem(itemProperties,
+ childItems,
+ reader);
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfAttribute> attribute =
+ shared_dynamic_cast<XdmfAttribute>(*iter)) {
+ this->insert(attribute);
+ }
+ }
+}
+
+void
+XdmfGraph::setTime(const shared_ptr<XdmfTime> time)
+{
+ mTime = time;
+ this->setIsChanged(true);
+}
+
+void
+XdmfGraph::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfSparseMatrix::traverse(visitor);
+ for (unsigned int i = 0; i < mAttributes.size(); ++i)
+ {
+ mAttributes[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+XDMFGRAPH * XdmfGraphNew(unsigned int numberNodes)
+{
+ try
+ {
+ shared_ptr<XdmfGraph> generatedGraph = XdmfGraph::New(numberNodes);
+ return (XDMFGRAPH *)((void *)(new XdmfGraph(*generatedGraph.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfGraph> generatedGraph = XdmfGraph::New(numberNodes);
+ return (XDMFGRAPH *)((void *)(new XdmfGraph(*generatedGraph.get())));
+ }
+}
+
+XDMFATTRIBUTE * XdmfGraphGetAttribute(XDMFGRAPH * graph, unsigned int index)
+{
+ return (XDMFATTRIBUTE *)((void *)(((XdmfGraph *)(graph))->getAttribute(index).get()));
+}
+
+XDMFATTRIBUTE * XdmfGraphGetAttributeByName(XDMFGRAPH * graph, char * Name)
+{
+ return (XDMFATTRIBUTE *)((void *)(((XdmfGraph *)(graph))->getAttribute(std::string(Name)).get()));
+}
+
+unsigned int XdmfGraphGetNumberAttributes(XDMFGRAPH * graph)
+{
+ return ((XdmfGraph *)graph)->getNumberAttributes();
+}
+
+void XdmfGraphInsertAttribute(XDMFGRAPH * graph, XDMFATTRIBUTE * Attribute, int passControl)
+{
+ if (passControl) {
+ ((XdmfGraph *)(graph))->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute));
+ }
+ else {
+ ((XdmfGraph *)(graph))->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute, XdmfNullDeleter()));
+ }
+}
+
+void XdmfGraphRemoveAttribute(XDMFGRAPH * graph, unsigned int index)
+{
+ ((XdmfGraph *)graph)->removeAttribute(index);
+}
+
+void XdmfGraphRemoveAttributeByName(XDMFGRAPH * graph, char * Name)
+{
+ ((XdmfGraph *)graph)->removeAttribute(std::string(Name));
+}
+
+unsigned int XdmfGraphGetNumberNodes(XDMFGRAPH * graph)
+{
+ return ((XdmfGraph *)graph)->getNumberNodes();
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfGraph, XDMFGRAPH)
+XDMF_SPARSEMATRIX_C_CHILD_WRAPPER(XdmfGraph, XDMFGRAPH)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGraph.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGRAPH_HPP_
+#define XDMFGRAPH_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfAttribute.hpp"
+#include "XdmfTime.hpp"
+#include "XdmfSparseMatrix.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Graph stored in sparse matrix form.
+ *
+ * Stores graph information in sparse matrix form. Attributes defining
+ * node and edge information can be inserted.
+ */
+class XDMF_EXPORT XdmfGraph : public XdmfSparseMatrix {
+
+public:
+
+ /**
+ * Create a new XdmfGraph.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGraph.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGraph.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param numberNodes number of nodes in graph.
+ *
+ * @return Constructed XdmfGraph.
+ */
+ static shared_ptr<XdmfGraph> New(const unsigned int numberNodes);
+
+ virtual ~XdmfGraph();
+
+ LOKI_DEFINE_VISITABLE(XdmfGraph, XdmfSparseMatrix)
+ XDMF_CHILDREN(XdmfGraph, XdmfAttribute, Attribute, Name)
+ static const std::string ItemTag;
+
+ std::string getItemTag() const;
+
+ shared_ptr<XdmfTime> getTime();
+
+ shared_ptr<const XdmfTime> getTime() const;
+
+ unsigned int getNumberNodes() const;
+
+ using XdmfSparseMatrix::insert;
+
+ void setTime(const shared_ptr<XdmfTime> time);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfGraph(XdmfGraph &);
+
+protected:
+
+ XdmfGraph(const unsigned int numberNodes);
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfGraph(const XdmfGraph &); // Not implemented.
+ void operator=(const XdmfGraph &); // Not implemented.
+
+ shared_ptr<XdmfTime> mTime;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFGRAPH; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRAPH XDMFGRAPH;
+
+XDMF_EXPORT XDMFGRAPH * XdmfGraphNew(unsigned int numberNodes);
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfGraphGetAttribute(XDMFGRAPH * graph, unsigned int index);
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfGraphGetAttributeByName(XDMFGRAPH * graph, char * Name);
+
+XDMF_EXPORT unsigned int XdmfGraphGetNumberAttributes(XDMFGRAPH * graph);
+
+XDMF_EXPORT void XdmfGraphInsertAttribute(XDMFGRAPH * graph, XDMFATTRIBUTE * Attribute, int passControl);
+
+XDMF_EXPORT void XdmfGraphRemoveAttribute(XDMFGRAPH * graph, unsigned int index);
+
+XDMF_EXPORT void XdmfGraphRemoveAttributeByName(XDMFGRAPH * graph, char * Name);
+
+XDMF_EXPORT unsigned int XdmfGraphGetNumberNodes(XDMFGRAPH * graph);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfGraph, XDMFGRAPH, XDMF)
+XDMF_SPARSEMATRIX_C_CHILD_DECLARE(XdmfGraph, XDMFGRAPH, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFGRAPH_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGrid.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include <string.h>
+#include "XdmfAttribute.hpp"
+#include "XdmfError.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfGrid.hpp"
+#include "XdmfMap.hpp"
+#include "XdmfSet.hpp"
+#include "XdmfTime.hpp"
+#include "XdmfTopology.hpp"
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfAttribute, Attribute, Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfMap, Map, Name)
+XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfSet, Set, Name)
+
+XdmfGrid::XdmfGrid(const shared_ptr<XdmfGeometry> geometry,
+ const shared_ptr<XdmfTopology> topology,
+ const std::string & name) :
+ mGeometry(geometry),
+ mTopology(topology),
+ mName(name),
+ mTime(shared_ptr<XdmfTime>())
+{
+}
+
+XdmfGrid::XdmfGrid(XdmfGrid &refGrid):
+ XdmfItem(refGrid),
+ mAttributes(refGrid.mAttributes),
+ mSets(refGrid.mSets),
+ mMaps(refGrid.mMaps),
+ mGeometry(refGrid.mGeometry),
+ mTopology(refGrid.mTopology),
+ mName(refGrid.mName),
+ mTime(refGrid.mTime)
+{
+ XdmfGridImpl * holder = refGrid.mImpl;
+ XdmfGridImpl * duplicateImpl = holder->duplicate();
+ mImpl = duplicateImpl;
+}
+
+XdmfGrid::~XdmfGrid()
+{
+}
+
+const std::string XdmfGrid::ItemTag = "Grid";
+
+shared_ptr<XdmfGridController>
+XdmfGrid::getGridController()
+{
+ return mGridController;
+}
+
+void
+XdmfGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
+{
+ this->setName(sourceGrid->getName());
+ this->setTime(sourceGrid->getTime());
+ while(this->getNumberAttributes() > 0)
+ {
+ this->removeAttribute(0);
+ }
+ for (unsigned int i = 0; i < sourceGrid->getNumberAttributes(); ++i)
+ {
+ this->insert(sourceGrid->getAttribute(i));
+ }
+ while(this->getNumberInformations() > 0)
+ {
+ this->removeInformation(0);
+ }
+ for (unsigned int i = 0; i < sourceGrid->getNumberInformations(); ++i)
+ {
+ this->insert(sourceGrid->getInformation(i));
+ }
+ while(this->getNumberSets() > 0)
+ {
+ this->removeSet(0);
+ }
+ for (unsigned int i = 0; i < sourceGrid->getNumberSets(); ++i)
+ {
+ this->insert(sourceGrid->getSet(i));
+ }
+ while(this->getNumberMaps() > 0)
+ {
+ this->removeMap(0);
+ }
+ for (unsigned int i = 0; i < sourceGrid->getNumberMaps(); ++i)
+ {
+ this->insert(sourceGrid->getMap(i));
+ }
+}
+
+shared_ptr<const XdmfGeometry>
+XdmfGrid::getGeometry() const
+{
+ return mGeometry;
+}
+
+std::map<std::string, std::string>
+XdmfGrid::getItemProperties() const
+{
+ std::map<std::string, std::string> gridProperties;
+ gridProperties.insert(std::make_pair("Name", mName));
+ return gridProperties;
+}
+
+std::string
+XdmfGrid::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::string
+XdmfGrid::getName() const
+{
+ return mName;
+}
+
+shared_ptr<XdmfTime>
+XdmfGrid::getTime()
+{
+ return boost::const_pointer_cast<XdmfTime>
+ (static_cast<const XdmfGrid &>(*this).getTime());
+}
+
+shared_ptr<const XdmfTime>
+XdmfGrid::getTime() const
+{
+ return mTime;
+}
+
+shared_ptr<const XdmfTopology>
+XdmfGrid::getTopology() const
+{
+ return mTopology;
+}
+
+void
+XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ std::map<std::string, std::string>::const_iterator name =
+ itemProperties.find("Name");
+ if(name != itemProperties.end()) {
+ mName = name->second;
+ }
+ else {
+ mName = "";
+ }
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfAttribute> attribute =
+ shared_dynamic_cast<XdmfAttribute>(*iter)) {
+ this->insert(attribute);
+ }
+ else if(shared_ptr<XdmfGeometry> geometry =
+ shared_dynamic_cast<XdmfGeometry>(*iter)) {
+ mGeometry = geometry;
+ }
+ else if(shared_ptr<XdmfMap> map =
+ shared_dynamic_cast<XdmfMap>(*iter)) {
+ this->insert(map);
+ }
+ else if(shared_ptr<XdmfSet> set =
+ shared_dynamic_cast<XdmfSet>(*iter)) {
+ this->insert(set);
+ }
+ else if(shared_ptr<XdmfTime> time =
+ shared_dynamic_cast<XdmfTime>(*iter)) {
+ mTime = time;
+ }
+ else if(shared_ptr<XdmfTopology> topology =
+ shared_dynamic_cast<XdmfTopology>(*iter)) {
+ mTopology = topology;
+ }
+ else if(shared_ptr<XdmfGridController> gridController =
+ shared_dynamic_cast<XdmfGridController>(*iter)) {
+ this->setGridController(gridController);
+ }
+ }
+}
+
+void
+XdmfGrid::read()
+{
+
+}
+
+void
+XdmfGrid::release()
+{
+ this->setName("");
+ this->setTime(shared_ptr<XdmfTime>());
+ while(this->getNumberAttributes() > 0)
+ {
+ this->removeAttribute(0);
+ }
+ while(this->getNumberInformations() > 0)
+ {
+ this->removeInformation(0);
+ }
+ while(this->getNumberSets() > 0)
+ {
+ this->removeSet(0);
+ }
+ while(this->getNumberMaps() > 0)
+ {
+ this->removeMap(0);
+ }
+}
+
+void
+XdmfGrid::setGridController(shared_ptr<XdmfGridController> newController)
+{
+ mGridController = newController;
+}
+
+
+void
+XdmfGrid::setName(const std::string & name)
+{
+ mName = name;
+ this->setIsChanged(true);
+}
+
+void
+XdmfGrid::setTime(const shared_ptr<XdmfTime> time)
+{
+ mTime = time;
+ this->setIsChanged(true);
+}
+
+void
+XdmfGrid::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+ if (mGridController) {
+ mGridController->accept(visitor);
+ }
+ if(mTime) {
+ mTime->accept(visitor);
+ }
+ if(mGeometry) {
+ mGeometry->accept(visitor);
+ }
+ if(mTopology) {
+ mTopology->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mAttributes.size(); ++i)
+ {
+ mAttributes[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mMaps.size(); ++i)
+ {
+ mMaps[i]->accept(visitor);
+ }
+ for (unsigned int i = 0; i < mSets.size(); ++i)
+ {
+ mSets[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+XDMFATTRIBUTE * XdmfGridGetAttribute(XDMFGRID * grid, unsigned int index)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return (XDMFATTRIBUTE *)((void *)(gridPointer->getAttribute(index).get()));
+}
+
+XDMFATTRIBUTE * XdmfGridGetAttributeByName(XDMFGRID * grid, char * Name)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return (XDMFATTRIBUTE *)((void *)(gridPointer->getAttribute(Name).get()));
+}
+
+unsigned int XdmfGridGetNumberAttributes(XDMFGRID * grid)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return gridPointer->getNumberAttributes();
+}
+
+void XdmfGridInsertAttribute(XDMFGRID * grid, XDMFATTRIBUTE * Attribute, int passControl)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ if (passControl) {
+ gridPointer->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute));
+ }
+ else {
+ gridPointer->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute, XdmfNullDeleter()));
+ }
+}
+
+void XdmfGridRemoveAttribute(XDMFGRID * grid, unsigned int index)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->removeAttribute(index);
+}
+
+void XdmfGridRemoveAttributeByName(XDMFGRID * grid, char * Name)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->removeAttribute(Name);
+}
+
+XDMFSET * XdmfGridGetSet(XDMFGRID * grid, unsigned int index)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return (XDMFSET *)((void *)(gridPointer->getSet(index).get()));
+}
+
+XDMFSET * XdmfGridGetSetByName(XDMFGRID * grid, char * Name)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return (XDMFSET *)((void *)(gridPointer->getSet(Name).get()));
+}
+
+unsigned int XdmfGridGetNumberSets(XDMFGRID * grid)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return gridPointer->getNumberSets();
+}
+
+void XdmfGridInsertSet(XDMFGRID * grid, XDMFSET * Set, int passControl)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ if (passControl) {
+ gridPointer->insert(shared_ptr<XdmfSet>((XdmfSet *)Set));
+ }
+ else {
+ gridPointer->insert(shared_ptr<XdmfSet>((XdmfSet *)Set, XdmfNullDeleter()));
+ }
+}
+
+void XdmfGridRemoveSet(XDMFGRID * grid, unsigned int index)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->removeSet(index);
+}
+
+void XdmfGridRemoveSetByName(XDMFGRID * grid, char * Name)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->removeSet(Name);
+}
+
+XDMFMAP * XdmfGridGetMap(XDMFGRID * grid, unsigned int index)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return (XDMFMAP *)((void *)(gridPointer->getMap(index).get()));
+}
+
+XDMFMAP * XdmfGridGetMapByName(XDMFGRID * grid, char * Name)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return (XDMFMAP *)((void *)(gridPointer->getMap(Name).get()));
+}
+
+unsigned int XdmfGridGetNumberMaps(XDMFGRID * grid)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return gridPointer->getNumberMaps();
+}
+
+void XdmfGridInsertMap(XDMFGRID * grid, XDMFMAP * Map, int passControl)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ if (passControl) {
+ gridPointer->insert(shared_ptr<XdmfMap>((XdmfMap *)Map));
+ }
+ else {
+ gridPointer->insert(shared_ptr<XdmfMap>((XdmfMap *)Map, XdmfNullDeleter()));
+ }
+}
+
+void XdmfGridRemoveMap(XDMFGRID * grid, unsigned int index)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->removeMap(index);
+}
+
+void XdmfGridRemoveMapByName(XDMFGRID * grid, char * Name)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->removeMap(Name);
+}
+
+XDMFGRIDCONTROLLER * XdmfGridGetGridController(XDMFGRID * grid)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ shared_ptr<XdmfGridController> generatedController = gridPointer->getGridController();
+ return (XDMFGRIDCONTROLLER *)((void *)(generatedController.get()));
+
+}
+
+char * XdmfGridGetName(XDMFGRID * grid)
+{
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ return strdup(gridPointer->getName().c_str());
+}
+
+XDMFTIME * XdmfGridGetTime(XDMFGRID * grid)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ shared_ptr<XdmfTime> generatedTime = gridPointer->getTime();
+ return (XDMFTIME *)((void *)(generatedTime.get()));
+}
+
+void
+XdmfGridRead(XDMFGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ gridPointer->read();
+ }
+ catch (...)
+ {
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ gridPointer->read();
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfGridRelease(XDMFGRID * grid)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ gridPointer->release();
+}
+
+void XdmfGridSetGridController(XDMFGRID * grid, XDMFGRIDCONTROLLER * controller, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ XdmfItem * controllerPointer = (XdmfItem *) controller;
+ XdmfGridController * classedController = dynamic_cast<XdmfGridController *>(controllerPointer);
+ if (passControl) {
+ gridPointer->setGridController(shared_ptr<XdmfGridController>(classedController));
+ }
+ else {
+ gridPointer->setGridController(shared_ptr<XdmfGridController>(classedController, XdmfNullDeleter()));
+ }
+}
+
+void XdmfGridSetName(XDMFGRID * grid, char * name, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * tempPointer = (XdmfItem *)(grid);
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(tempPointer);
+ gridPointer->setName(name);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfGridSetTime(XDMFGRID * grid, XDMFTIME * time, int passControl)
+{
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * gridPointer = dynamic_cast<XdmfGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setTime(shared_ptr<XdmfTime>((XdmfTime *)time));
+ }
+ else {
+ gridPointer->setTime(shared_ptr<XdmfTime>((XdmfTime *)time, XdmfNullDeleter()));
+ }
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfGrid, XDMFGRID)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGrid.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGRID_HPP_
+#define XDMFGRID_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfAttribute.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfGridController.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfMap.hpp"
+#include "XdmfSet.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfSubGrid;
+class XdmfTime;
+
+/**
+ * @brief A mesh containing elements, points, and fields attached to
+ * the mesh.
+ *
+ * XdmfGrid represents a mesh. It is required to contain two other
+ * Xdmf data structures, an XdmfGeometry that stores point locations
+ * and an XdmfTopology that store connectivity
+ * information. XdmfAttributes can be inserted into the XdmfGrid to
+ * specify fields centered on various parts of the mesh. XdmfSets can
+ * be inserted into XdmfGrids to specify collections of mesh elements.
+ *
+ * XdmfGrid is an abstract base class. There are several
+ * implementations for representing both structured and unstructured
+ * grids.
+ */
+class XDMF_EXPORT XdmfGrid : public virtual XdmfItem {
+
+public:
+
+ virtual ~XdmfGrid();
+
+ LOKI_DEFINE_VISITABLE(XdmfGrid, XdmfItem)
+ XDMF_CHILDREN(XdmfGrid, XdmfAttribute, Attribute, Name)
+ XDMF_CHILDREN(XdmfGrid, XdmfSet, Set, Name)
+ XDMF_CHILDREN(XdmfGrid, XdmfMap, Map, Name)
+ static const std::string ItemTag;
+
+ /**
+ * Get the geometry associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getGeometry
+ * @until //#getGeometry
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getGeometry
+ * @until #//getGeometry
+ *
+ * @return The geometry associated with this grid.
+ */
+ virtual shared_ptr<const XdmfGeometry> getGeometry() const;
+
+ /**
+ * Gets the current external reference for this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGridController
+ * @until //#setGridController
+ * @skipline //#getGridController
+ * @until //#getGridController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGridController
+ * @until #//setGridController
+ * @skipline #//getGridController
+ * @until #//getGridController
+ *
+ * @return The current reference.
+ */
+ shared_ptr<XdmfGridController> getGridController();
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ virtual std::string getItemTag() const;
+
+ /**
+ * Get the name of the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return The name of the grid.
+ */
+ std::string getName() const;
+
+ /**
+ * Get the time associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setTime
+ * @until //#setTime
+ * @skipline //#getTime
+ * @until //#getTime
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setTime
+ * @until #//setTime
+ * @skipline #//getTime
+ * @until #//getTime
+ *
+ * @return Pointer to the XdmfTime attached to this grid. If no
+ * XdmfTime is attached, return a NULL pointer.
+ */
+ virtual shared_ptr<XdmfTime> getTime();
+
+ /**
+ * Get the time associated with this grid (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setTime
+ * @until //#setTime
+ * @skipline //#getTimeconst
+ * @until //#getTimeconst
+ *
+ * Python: Python doesn't have a constant version
+ *
+ * @return Pointer to the XdmfTime attached to this grid. If no
+ * XdmfTime is attached, return a NULL pointer.
+ */
+ virtual shared_ptr<const XdmfTime> getTime() const;
+
+ /**
+ * Get the topology associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getTopology
+ * @until //#getTopology
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getTopology
+ * @until #//getTopology
+ *
+ * @return The topology associated with this grid.
+ */
+ virtual shared_ptr<const XdmfTopology> getTopology() const;
+
+ using XdmfItem::insert;
+
+ /**
+ * Reads the tree structure fromt he grid controller set to this grid
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//read
+ * @until #//read
+ */
+ virtual void read();
+
+ /**
+ * Releases the grid structure that this grid contains.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#release
+ * @until //#release
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//release
+ * @until #//release
+ */
+ virtual void release();
+
+ /**
+ * Sets the reference to an external xdmf tree from which to populate the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGridController
+ * @until //#setGridController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGridController
+ * @until #//setGridController
+ *
+ * @param newController A reference to the external tree.
+ */
+ void setGridController(shared_ptr<XdmfGridController> newController);
+
+ /**
+ * Set the name of the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ *
+ * @param name Name of the grid to set.
+ */
+ void setName(const std::string & name);
+
+ /**
+ * Set the time associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setTime
+ * @until //#setTime
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setTime
+ * @until #//setTime
+ *
+ * @param time An XdmfTime to associate with this grid.
+ */
+ virtual void setTime(const shared_ptr<XdmfTime> time);
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfGrid(XdmfGrid &);
+
+protected:
+
+ XdmfGrid(const shared_ptr<XdmfGeometry> geometry,
+ const shared_ptr<XdmfTopology> topology,
+ const std::string & name = "Grid");
+
+ virtual void
+ copyGrid(shared_ptr<XdmfGrid> sourceGrid);
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+ shared_ptr<XdmfGeometry> mGeometry;
+ shared_ptr<XdmfTopology> mTopology;
+
+ class XdmfGridImpl
+ {
+ public:
+ XdmfGridImpl()
+ {
+ }
+
+ virtual ~XdmfGridImpl()
+ {
+ }
+
+ virtual XdmfGridImpl * duplicate() = 0;
+
+ std::string getGridType() const
+ {
+ return mGridType;
+ }
+
+ std::string mGridType;
+ };
+
+ XdmfGridImpl * mImpl;
+
+ shared_ptr<XdmfGridController> mGridController;
+
+private:
+
+ XdmfGrid(const XdmfGrid &); // Not implemented.
+ void operator=(const XdmfGrid &); // Not implemented.
+
+ std::string mName;
+ shared_ptr<XdmfTime> mTime;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#ifndef XDMFGRIDCDEFINE
+#define XDMFGRIDCDEFINE
+struct XDMFGRID; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRID XDMFGRID;
+#endif
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfGridGetAttribute(XDMFGRID * grid, unsigned int index);
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfGridGetAttributeByName(XDMFGRID * grid, char * Name);
+
+XDMF_EXPORT unsigned int XdmfGridGetNumberAttributes(XDMFGRID * grid);
+
+XDMF_EXPORT void XdmfGridInsertAttribute(XDMFGRID * grid, XDMFATTRIBUTE * Attribute, int passControl);
+
+XDMF_EXPORT void XdmfGridRemoveAttribute(XDMFGRID * grid, unsigned int index);
+
+XDMF_EXPORT void XdmfGridRemoveAttributeByName(XDMFGRID * grid, char * Name);
+
+XDMF_EXPORT XDMFSET * XdmfGridGetSet(XDMFGRID * grid, unsigned int index);
+
+XDMF_EXPORT XDMFSET * XdmfGridGetSetByName(XDMFGRID * grid, char * Name);
+
+XDMF_EXPORT unsigned int XdmfGridGetNumberSets(XDMFGRID * grid);
+
+XDMF_EXPORT void XdmfGridInsertSet(XDMFGRID * grid, XDMFSET * Set, int passControl);
+
+XDMF_EXPORT void XdmfGridRemoveSet(XDMFGRID * grid, unsigned int index);
+
+XDMF_EXPORT void XdmfGridRemoveSetByName(XDMFGRID * grid, char * Name);
+
+XDMF_EXPORT XDMFMAP * XdmfGridGetMap(XDMFGRID * grid, unsigned int index);
+
+XDMF_EXPORT XDMFMAP * XdmfGridGetMapByName(XDMFGRID * grid, char * Name);
+
+XDMF_EXPORT unsigned int XdmfGridGetNumberMaps(XDMFGRID * grid);
+
+XDMF_EXPORT void XdmfGridInsertMap(XDMFGRID * grid, XDMFMAP * Map, int passControl);
+
+XDMF_EXPORT void XdmfGridRemoveMap(XDMFGRID * grid, unsigned int index);
+
+XDMF_EXPORT void XdmfGridRemoveMapByName(XDMFGRID * grid, char * Name);
+
+XDMF_EXPORT XDMFGRIDCONTROLLER * XdmfGridGetGridController(XDMFGRID * grid);
+
+XDMF_EXPORT char * XdmfGridGetName(XDMFGRID * grid);
+
+XDMF_EXPORT XDMFTIME * XdmfGridGetTime(XDMFGRID * grid);
+
+XDMF_EXPORT void XdmfGridRead(XDMFGRID * grid, int * status);
+
+XDMF_EXPORT void XdmfGridRelease(XDMFGRID * grid);
+
+XDMF_EXPORT void XdmfGridSetGridController(XDMFGRID * grid, XDMFGRIDCONTROLLER * controller, int passControl);
+
+XDMF_EXPORT void XdmfGridSetName(XDMFGRID * grid, char * name, int * status);
+
+XDMF_EXPORT void XdmfGridSetTime(XDMFGRID * grid, XDMFTIME * time, int passControl);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfGrid, XDMFGRID, XDMF)
+
+#define XDMF_GRID_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT XDMFATTRIBUTE * ClassName##GetAttribute(CClassName * grid, unsigned int index); \
+Level##_EXPORT XDMFATTRIBUTE * ClassName##GetAttributeByName(CClassName * grid, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberAttributes(CClassName * grid); \
+Level##_EXPORT void ClassName##InsertAttribute(CClassName * grid, XDMFATTRIBUTE * Attribute, int passControl); \
+Level##_EXPORT void ClassName##RemoveAttribute(CClassName * grid, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveAttributeByName(CClassName * grid, char * Name); \
+Level##_EXPORT XDMFSET * ClassName##GetSet(CClassName * grid, unsigned int index); \
+Level##_EXPORT XDMFSET * ClassName##GetSetByName(CClassName * grid, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberSets(CClassName * grid); \
+Level##_EXPORT void ClassName##InsertSet(CClassName * grid, XDMFSET * Set, int passControl); \
+Level##_EXPORT void ClassName##RemoveSet(CClassName * grid, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveSetByName(CClassName * grid, char * Name); \
+Level##_EXPORT XDMFMAP * ClassName##GetMap(CClassName * grid, unsigned int index); \
+Level##_EXPORT XDMFMAP * ClassName##GetMapByName(CClassName * grid, char * Name); \
+Level##_EXPORT unsigned int ClassName##GetNumberMaps(CClassName * grid); \
+Level##_EXPORT void ClassName##InsertMap(CClassName * grid, XDMFMAP * Map, int passControl); \
+Level##_EXPORT void ClassName##RemoveMap(CClassName * grid, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveMapByName(CClassName * grid, char * Name); \
+Level##_EXPORT XDMFGRIDCONTROLLER * ClassName##GetGridController(CClassName * grid); \
+Level##_EXPORT char * ClassName##GetName(CClassName * grid); \
+Level##_EXPORT XDMFTIME * ClassName##GetTime(CClassName * grid); \
+Level##_EXPORT void ClassName##Read( CClassName * grid, int * status); \
+Level##_EXPORT void ClassName##Release( CClassName * grid); \
+Level##_EXPORT void ClassName##SetGridController(CClassName * grid, XDMFGRIDCONTROLLER * controller, int passControl); \
+Level##_EXPORT void ClassName##SetName(CClassName * grid, char * name, int * status); \
+Level##_EXPORT void ClassName##SetTime(CClassName * grid, XDMFTIME * time, int passControl);
+
+
+
+#define XDMF_GRID_C_CHILD_WRAPPER(ClassName, CClassName) \
+XDMFATTRIBUTE * ClassName##GetAttribute(CClassName * grid, unsigned int index) \
+{ \
+ return XdmfGridGetAttribute((XDMFGRID *)((void *)grid), index); \
+} \
+ \
+XDMFATTRIBUTE * ClassName##GetAttributeByName(CClassName * grid, char * Name) \
+{ \
+ return XdmfGridGetAttributeByName((XDMFGRID *)((void *)grid), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberAttributes(CClassName * grid) \
+{ \
+ return XdmfGridGetNumberAttributes((XDMFGRID *)((void *)grid)); \
+} \
+ \
+void ClassName##InsertAttribute(CClassName * grid, XDMFATTRIBUTE * Attribute, int passControl) \
+{ \
+ XdmfGridInsertAttribute((XDMFGRID *)((void *)grid), Attribute, passControl); \
+} \
+ \
+void ClassName##RemoveAttribute(CClassName * grid, unsigned int index) \
+{ \
+ XdmfGridRemoveAttribute((XDMFGRID *)((void *)grid), index); \
+} \
+ \
+void ClassName##RemoveAttributeByName(CClassName * grid, char * Name) \
+{ \
+ XdmfGridRemoveAttributeByName((XDMFGRID *)((void *)grid), Name); \
+} \
+ \
+XDMFSET * ClassName##GetSet(CClassName * grid, unsigned int index) \
+{ \
+ return XdmfGridGetSet((XDMFGRID *)((void *)grid), index); \
+} \
+ \
+XDMFSET * ClassName##GetSetByName(CClassName * grid, char * Name) \
+{ \
+ return XdmfGridGetSetByName((XDMFGRID *)((void *)grid), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberSets(CClassName * grid) \
+{ \
+ return XdmfGridGetNumberSets((XDMFGRID *)((void *)grid)); \
+} \
+ \
+void ClassName##InsertSet(CClassName * grid, XDMFSET * Set, int passControl) \
+{ \
+ XdmfGridInsertSet((XDMFGRID *)((void *)grid), Set, passControl); \
+} \
+ \
+void ClassName##RemoveSet(CClassName * grid, unsigned int index) \
+{ \
+ XdmfGridRemoveSet((XDMFGRID *)((void *)grid), index); \
+} \
+ \
+void ClassName##RemoveSetByName(CClassName * grid, char * Name) \
+{ \
+ XdmfGridRemoveSetByName((XDMFGRID *)((void *)grid), Name); \
+} \
+ \
+XDMFMAP * ClassName##GetMap(CClassName * grid, unsigned int index) \
+{ \
+ return XdmfGridGetMap((XDMFGRID *)((void *)grid), index); \
+} \
+ \
+XDMFMAP * ClassName##GetMapByName(CClassName * grid, char * Name) \
+{ \
+ return XdmfGridGetMapByName((XDMFGRID *)((void *)grid), Name); \
+} \
+ \
+unsigned int ClassName##GetNumberMaps(CClassName * grid) \
+{ \
+ return XdmfGridGetNumberMaps((XDMFGRID *)((void *)grid)); \
+} \
+ \
+void ClassName##InsertMap(CClassName * grid, XDMFMAP * Map, int passControl) \
+{ \
+ XdmfGridInsertMap((XDMFGRID *)((void *)grid), Map, passControl); \
+} \
+ \
+void ClassName##RemoveMap(CClassName * grid, unsigned int index) \
+{ \
+ XdmfGridRemoveMap((XDMFGRID *)((void *)grid), index); \
+} \
+ \
+void ClassName##RemoveMapByName(CClassName * grid, char * Name) \
+{ \
+ XdmfGridRemoveMapByName((XDMFGRID *)((void *)grid), Name); \
+} \
+ \
+XDMFGRIDCONTROLLER * ClassName##GetGridController(CClassName * grid) \
+{ \
+ return XdmfGridGetGridController((XDMFGRID *)((void *)grid)); \
+} \
+ \
+char * ClassName##GetName(CClassName * grid) \
+{ \
+ return XdmfGridGetName((XDMFGRID *)((void *)grid)); \
+} \
+ \
+XDMFTIME * ClassName##GetTime(CClassName * grid) \
+{ \
+ return XdmfGridGetTime((XDMFGRID *)((void *)grid)); \
+} \
+ \
+void \
+ClassName##Read( CClassName * grid, int * status) \
+{ \
+ XdmfGridRead((XDMFGRID *)((void *)grid), status); \
+} \
+ \
+void \
+ClassName##Release( CClassName * grid) \
+{ \
+ XdmfGridRelease((XDMFGRID *)((void *)grid)); \
+} \
+ \
+void ClassName##SetGridController(CClassName * grid, XDMFGRIDCONTROLLER * controller, int passControl) \
+{ \
+ XdmfGridSetGridController((XDMFGRID *)((void *)grid), controller, passControl); \
+} \
+ \
+void ClassName##SetName(CClassName * grid, char * name, int * status) \
+{ \
+ XdmfGridSetName((XDMFGRID *)((void *)grid), name, status); \
+} \
+ \
+void ClassName##SetTime(CClassName * grid, XDMFTIME * time, int passControl) \
+{ \
+ XdmfGridSetTime((XDMFGRID *)((void *)grid), time, passControl); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFGRID_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGridCollection.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfError.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfGridCollectionType.hpp"
+
+class XdmfGridCollection::XdmfGridCollectionImpl : public XdmfGridImpl
+{
+ public:
+ XdmfGridCollectionImpl()
+ {
+ mGridType = "Collection";
+ }
+
+ ~XdmfGridCollectionImpl()
+ {
+ }
+
+ XdmfGridImpl * duplicate()
+ {
+ return new XdmfGridCollectionImpl();
+ }
+
+ std::string getGridType() const
+ {
+ return mGridType;
+ }
+};
+
+shared_ptr<XdmfGridCollection>
+XdmfGridCollection::New()
+{
+ shared_ptr<XdmfGridCollection> p(new XdmfGridCollection());
+ return p;
+}
+
+XdmfGridCollection::XdmfGridCollection() :
+ XdmfDomain(),
+ XdmfGrid(shared_ptr<XdmfGeometry>(), shared_ptr<XdmfTopology>(), "Collection"),
+ mType(XdmfGridCollectionType::NoCollectionType())
+{
+ mImpl = new XdmfGridCollectionImpl();
+}
+
+XdmfGridCollection::XdmfGridCollection(XdmfGridCollection & refCollection) :
+ XdmfDomain(refCollection),
+ XdmfGrid(refCollection),
+ mType(refCollection.mType)
+{
+}
+
+XdmfGridCollection::~XdmfGridCollection()
+{
+ if (mImpl) {
+ delete mImpl;
+ }
+ mImpl = NULL;
+}
+
+const std::string XdmfGridCollection::ItemTag = "Grid";
+
+void
+XdmfGridCollection::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
+{
+ XdmfGrid::copyGrid(sourceGrid);
+ if (shared_ptr<XdmfGridCollection> classedGrid = shared_dynamic_cast<XdmfGridCollection>(sourceGrid))
+ {
+ // Copy stucture from read grid to this grid
+ while (this->getNumberGridCollections() > 0)
+ {
+ this->removeGridCollection(0);
+ }
+ for (unsigned int i = 0; i < classedGrid->getNumberGridCollections(); ++i)
+ {
+ this->insert(classedGrid->getGridCollection(i));
+ }
+ while (this->getNumberCurvilinearGrids() > 0)
+ {
+ this->removeCurvilinearGrid(0);
+ }
+ for (unsigned int i = 0; i < classedGrid->getNumberCurvilinearGrids(); ++i)
+ {
+ this->insert(classedGrid->getCurvilinearGrid(i));
+ }
+ while (this->getNumberGraphs() > 0)
+ {
+ this->removeGraph(0);
+ }
+ for (unsigned int i = 0; i < classedGrid->getNumberGraphs(); ++i)
+ {
+ this->insert(classedGrid->getGraph(i));
+ }
+ while (this->getNumberRectilinearGrids() > 0)
+ {
+ this->removeRectilinearGrid(0);
+ }
+ for (unsigned int i = 0; i < classedGrid->getNumberRectilinearGrids(); ++i)
+ {
+ this->insert(classedGrid->getRectilinearGrid(i));
+ }
+ while (this->getNumberRegularGrids() > 0)
+ {
+ this->removeRegularGrid(0);
+ }
+ for (unsigned int i = 0; i < classedGrid->getNumberRegularGrids(); ++i)
+ {
+ this->insert(classedGrid->getRegularGrid(i));
+ }
+ while (this->getNumberUnstructuredGrids() > 0)
+ {
+ this->removeUnstructuredGrid(0);
+ }
+ for (unsigned int i = 0; i < classedGrid->getNumberUnstructuredGrids(); ++i)
+ {
+ this->insert(classedGrid->getUnstructuredGrid(i));
+ }
+ }
+}
+
+std::map<std::string, std::string>
+XdmfGridCollection::getItemProperties() const
+{
+ std::map<std::string, std::string> collectionProperties =
+ XdmfGrid::getItemProperties();
+ collectionProperties.insert(std::make_pair("GridType", "Collection"));
+ mType->getProperties(collectionProperties);
+ return collectionProperties;
+}
+
+std::string
+XdmfGridCollection::getItemTag() const
+{
+ return ItemTag;
+}
+
+shared_ptr<const XdmfGridCollectionType>
+XdmfGridCollection::getType() const
+{
+ return mType;
+}
+
+void
+XdmfGridCollection::insert(const shared_ptr<XdmfInformation> information)
+{
+ XdmfItem::insert(information);
+}
+
+void
+XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ mType = XdmfGridCollectionType::New(itemProperties);
+ XdmfDomain::populateItem(itemProperties, childItems, reader);
+ mInformations.clear();
+ XdmfGrid::populateItem(itemProperties, childItems, reader);
+}
+
+void
+XdmfGridCollection::read()
+{
+ if (mGridController)
+ {
+ if (shared_ptr<XdmfGridCollection> grid = shared_dynamic_cast<XdmfGridCollection>(mGridController->read()))
+ {
+ // Copy stucture from read grid to this grid
+ while(this->getNumberGridCollections() > 0)
+ {
+ this->removeGridCollection(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberGridCollections(); ++i)
+ {
+ this->insert(grid->getGridCollection(i));
+ }
+ while(this->getNumberUnstructuredGrids() > 0)
+ {
+ this->removeUnstructuredGrid(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberUnstructuredGrids(); ++i)
+ {
+ this->insert(grid->getUnstructuredGrid(i));
+ }
+ while(this->getNumberCurvilinearGrids() > 0)
+ {
+ this->removeCurvilinearGrid(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberCurvilinearGrids(); ++i)
+ {
+ this->insert(grid->getCurvilinearGrid(i));
+ }
+ while(this->getNumberRectilinearGrids() > 0)
+ {
+ this->removeRectilinearGrid(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberRectilinearGrids(); ++i)
+ {
+ this->insert(grid->getRectilinearGrid(i));
+ }
+ while(this->getNumberRegularGrids() > 0)
+ {
+ this->removeRegularGrid(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberRegularGrids(); ++i)
+ {
+ this->insert(grid->getRegularGrid(i));
+ }
+ while(this->getNumberAttributes() > 0)
+ {
+ this->removeAttribute(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberAttributes(); ++i)
+ {
+ this->insert(grid->getAttribute(i));
+ }
+ while(this->getNumberInformations() > 0)
+ {
+ this->removeInformation(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberInformations(); ++i)
+ {
+ this->insert(grid->getInformation(i));
+ }
+ while(this->getNumberSets() > 0)
+ {
+ this->removeSet(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberSets(); ++i)
+ {
+ this->insert(grid->getSet(i));
+ }
+ while(this->getNumberMaps() > 0)
+ {
+ this->removeMap(0);
+ }
+ for (unsigned int i = 0; i < grid->getNumberMaps(); ++i)
+ {
+ this->insert(grid->getMap(i));
+ }
+ }
+ else if (shared_dynamic_cast<XdmfGrid>(mGridController->read()))
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference");
+ }
+ }
+}
+
+void
+XdmfGridCollection::release()
+{
+ while(this->getNumberGridCollections() > 0)
+ {
+ this->removeGridCollection(0);
+ }
+ while(this->getNumberUnstructuredGrids() > 0)
+ {
+ this->removeUnstructuredGrid(0);
+ }
+ while(this->getNumberCurvilinearGrids() > 0)
+ {
+ this->removeCurvilinearGrid(0);
+ }
+ while(this->getNumberRectilinearGrids() > 0)
+ {
+ this->removeRectilinearGrid(0);
+ }
+ while(this->getNumberRegularGrids() > 0)
+ {
+ this->removeRegularGrid(0);
+ }
+ while(this->getNumberAttributes() > 0)
+ {
+ this->removeAttribute(0);
+ }
+ while(this->getNumberInformations() > 0)
+ {
+ this->removeInformation(0);
+ }
+ while(this->getNumberSets() > 0)
+ {
+ this->removeSet(0);
+ }
+ while(this->getNumberMaps() > 0)
+ {
+ this->removeMap(0);
+ }
+}
+
+void
+XdmfGridCollection::setType(const shared_ptr<const XdmfGridCollectionType> type)
+{
+ mType = type;
+ this->setIsChanged(true);
+}
+
+void
+XdmfGridCollection::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfGrid::traverse(visitor);
+
+ // Only write XdmfInformations once (deal with diamond inheritance)
+ std::vector<shared_ptr<XdmfInformation> > informations;
+ informations.swap(mInformations);
+ XdmfDomain::traverse(visitor);
+ informations.swap(mInformations);
+}
+
+// C Wrappers
+
+XDMFGRIDCOLLECTION * XdmfGridCollectionNew()
+{
+ try
+ {
+ XDMFGRIDCOLLECTION * returnCollection = NULL;
+ shared_ptr<XdmfGridCollection> generatedCollection = XdmfGridCollection::New();
+ returnCollection = (XDMFGRIDCOLLECTION *)((void *)((XdmfItem *)(new XdmfGridCollection(*generatedCollection.get()))));
+ generatedCollection.reset();
+ return returnCollection;
+ }
+ catch (...)
+ {
+ XDMFGRIDCOLLECTION * returnCollection = NULL;
+ shared_ptr<XdmfGridCollection> generatedCollection = XdmfGridCollection::New();
+ returnCollection = (XDMFGRIDCOLLECTION *)((void *)((XdmfItem *)(new XdmfGridCollection(*generatedCollection.get()))));
+ generatedCollection.reset();
+ return returnCollection;
+ }
+}
+
+int XdmfGridCollectionGetType(XDMFGRIDCOLLECTION * collection, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * tempPointer = (XdmfItem *)collection;
+ XdmfGridCollection * tempCollection = dynamic_cast<XdmfGridCollection *>(tempPointer);
+ shared_ptr<const XdmfGridCollectionType> checkType = tempCollection->getType();
+ if (checkType == XdmfGridCollectionType::NoCollectionType()) {
+ return XDMF_GRID_COLLECTION_TYPE_NO_COLLECTION_TYPE;
+ }
+ else if (checkType == XdmfGridCollectionType::Spatial()) {
+ return XDMF_GRID_COLLECTION_TYPE_SPATIAL;
+ }
+ else if (checkType == XdmfGridCollectionType::Temporal()) {
+ return XDMF_GRID_COLLECTION_TYPE_TEMPORAL;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+void XdmfGridCollectionSetType(XDMFGRIDCOLLECTION * collection, int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * tempPointer = (XdmfItem *)collection;
+ XdmfGridCollection * tempCollection = dynamic_cast<XdmfGridCollection *>(tempPointer);
+ switch (type) {
+ case XDMF_GRID_COLLECTION_TYPE_NO_COLLECTION_TYPE:
+ tempCollection->setType(XdmfGridCollectionType::NoCollectionType());
+ break;
+ case XDMF_GRID_COLLECTION_TYPE_SPATIAL:
+ tempCollection->setType(XdmfGridCollectionType::Spatial());
+ break;
+ case XDMF_GRID_COLLECTION_TYPE_TEMPORAL:
+ tempCollection->setType(XdmfGridCollectionType::Temporal());
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMF_DOMAIN_C_CHILD_WRAPPER(XdmfGridCollection, XDMFGRIDCOLLECTION)
+XDMF_GRID_C_CHILD_WRAPPER(XdmfGridCollection, XDMFGRIDCOLLECTION)
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfGridCollection, XDMFGRIDCOLLECTION)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGridCollection.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGRIDCOLLECTION_HPP_
+#define XDMFGRIDCOLLECTION_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfDomain.hpp"
+#include "XdmfGrid.hpp"
+#include "XdmfGridCollectionType.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief A spatial or temporal collection of XdmfGrids.
+ *
+ * A temporal collection is timestep data. Each child grid represents
+ * the state at a single timestep. A spatial collection consists of
+ * XdmfGrids that are arranged together in space. E.g. a partitioned
+ * mesh.
+ *
+ * It is valid to nest collections. A spatial collection inside a
+ * temporal collection is commonly used.
+ */
+class XDMF_EXPORT XdmfGridCollection : public virtual XdmfDomain,
+ public XdmfGrid {
+
+public:
+
+ /**
+ * Create a new XdmfGridCollection.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGridCollection.cpp
+ * @skipline //#initalization
+ * @until //#initalization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGridCollection.py
+ * @skipline #//initalization
+ * @until #//initalization
+ *
+ * @return Constructed XdmfGridCollection.
+ */
+ static shared_ptr<XdmfGridCollection> New();
+
+ virtual ~XdmfGridCollection();
+
+ LOKI_DEFINE_VISITABLE(XdmfGridCollection, XdmfGrid)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the XdmfGridCollectionType associated with this grid collection.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGridCollection.cpp
+ * @skipline //#initalization
+ * @until //#initalization
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGridCollection.py
+ * @skipline #//initalization
+ * @until #//initalization
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * @return XdmfGridCollectionType of this collection.
+ */
+ shared_ptr<const XdmfGridCollectionType> getType() const;
+
+ using XdmfDomain::insert;
+ using XdmfGrid::insert;
+
+ /**
+ * Insert an information into the grid collection.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGridCollection.cpp
+ * @skipline //#initalization
+ * @until //#initalization
+ * @skipline //#insert
+ * @until //#insert
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGridCollection.py
+ * @skipline #//initalization
+ * @until #//initalization
+ * @skipline #//insert
+ * @until #//insert
+ *
+ * @param information An XdmfInformation to attach to this item.
+ */
+ void insert(const shared_ptr<XdmfInformation> information);
+
+ void read();
+
+ void release();
+
+ /**
+ * Set the XdmfGridCollectionType associated with this grid
+ * collection.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGridCollection.cpp
+ * @skipline //#initalization
+ * @until //#initalization
+ * @skipline //#setType
+ * @until //#setType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGridCollection.py
+ * @skipline #//initalization
+ * @until #//initalization
+ * @skipline #//setType
+ * @until #//setType
+ *
+ * @param type The XdmfGridCollectionType to set.
+ */
+ void setType(const shared_ptr<const XdmfGridCollectionType> type);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfGridCollection(XdmfGridCollection &);
+
+protected:
+
+ XdmfGridCollection();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+ void copyGrid(shared_ptr<XdmfGrid> sourceGrid);
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfGridCollectionImpl;
+
+ XdmfGridCollection(const XdmfGridCollection &); // Not implemented.
+ void operator=(const XdmfGridCollection &); // Not implemented.
+
+ shared_ptr<const XdmfGridCollectionType> mType;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#ifndef XDMFGRIDCOLLECTIONCDEFINE
+#define XDMFGRIDCOLLECTIONCDEFINE
+struct XDMFGRIDCOLLECTION; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRIDCOLLECTION XDMFGRIDCOLLECTION;
+#endif
+
+XDMF_EXPORT XDMFGRIDCOLLECTION * XdmfGridCollectionNew();
+
+XDMF_EXPORT int XdmfGridCollectionGetType(XDMFGRIDCOLLECTION * collection, int * status);
+
+XDMF_EXPORT void XdmfGridCollectionSetType(XDMFGRIDCOLLECTION * collection, int type, int * status);
+
+XDMF_DOMAIN_C_CHILD_DECLARE(XdmfGridCollection, XDMFGRIDCOLLECTION, XDMF)
+XDMF_GRID_C_CHILD_DECLARE(XdmfGridCollection, XDMFGRIDCOLLECTION, XDMF)
+XDMF_ITEM_C_CHILD_DECLARE(XdmfGridCollection, XDMFGRIDCOLLECTION, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFGRID_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGridCollectionType.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfError.hpp"
+#include "XdmfGridCollectionType.hpp"
+
+std::map<std::string, shared_ptr<const XdmfGridCollectionType>(*)()>
+ XdmfGridCollectionType::mGridCollectionDefinitions;
+
+// Supported XdmfGridCollectionTypes
+shared_ptr<const XdmfGridCollectionType>
+XdmfGridCollectionType::NoCollectionType()
+{
+ static shared_ptr<const XdmfGridCollectionType>
+ p(new XdmfGridCollectionType("None"));
+ return p;
+}
+
+shared_ptr<const XdmfGridCollectionType>
+XdmfGridCollectionType::Spatial()
+{
+ static shared_ptr<const XdmfGridCollectionType>
+ p(new XdmfGridCollectionType("Spatial"));
+ return p;
+}
+
+shared_ptr<const XdmfGridCollectionType>
+XdmfGridCollectionType::Temporal()
+{
+ static shared_ptr<const XdmfGridCollectionType>
+ p(new XdmfGridCollectionType("Temporal"));
+ return p;
+}
+
+void
+XdmfGridCollectionType::InitTypes()
+{
+ mGridCollectionDefinitions["NONE"] = NoCollectionType;
+ mGridCollectionDefinitions["SPATIAL"] = Spatial;
+ mGridCollectionDefinitions["TEMPORAL"] = Temporal;
+}
+
+XdmfGridCollectionType::XdmfGridCollectionType(const std::string & name) :
+ mName(name)
+{
+}
+
+XdmfGridCollectionType::~XdmfGridCollectionType()
+{
+}
+
+shared_ptr<const XdmfGridCollectionType>
+XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("CollectionType");
+ if(type == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'CollectionType' not in itemProperties in "
+ "XdmfGridCollectionType::New");
+ }
+
+ const std::string & typeVal = ConvertToUpper(type->second);
+
+ std::map<std::string, shared_ptr<const XdmfGridCollectionType>(*)()>::const_iterator returnType
+ = mGridCollectionDefinitions.find(typeVal);
+
+ if (returnType == mGridCollectionDefinitions.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'CollectionType' not of 'None', 'Spatial', or "
+ "'Temporal' in XdmfGridCollectionType::New");
+ }
+ else {
+ return (*(returnType->second))();
+ }
+
+ XdmfError::message(XdmfError::FATAL,
+ "'CollectionType' not of 'None', 'Spatial', or "
+ "'Temporal' in XdmfGridCollectionType::New");
+
+ // unreachable
+ return shared_ptr<const XdmfGridCollectionType>();
+}
+
+void
+XdmfGridCollectionType::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("CollectionType", mName));
+}
+
+// C Wrappers
+
+int XdmfGridCollectionTypeNoCollectionType()
+{
+ return XDMF_GRID_COLLECTION_TYPE_NO_COLLECTION_TYPE;
+}
+
+int XdmfGridCollectionTypeSpatial()
+{
+ return XDMF_GRID_COLLECTION_TYPE_SPATIAL;
+}
+
+int XdmfGridCollectionTypeTemporal()
+{
+ return XDMF_GRID_COLLECTION_TYPE_TEMPORAL;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGridCollectionType.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGRIDCOLLECTIONTYPE_HPP_
+#define XDMFGRIDCOLLECTIONTYPE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include "XdmfItemProperty.hpp"
+
+/**
+ * @brief Property describing the type of an XdmfGridCollection.
+ *
+ * XdmfGridCollectionType is a property used by XdmfGridCollection to
+ * specify what type of collection the XdmfGridCollection contains. A
+ * specific XdmfGridCollectionType can be created by calling one of
+ * the static methods in the class,
+ * i.e. XdmfGridCollectionType::Temporal().
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGridCollection.cpp
+ * @skipline //#initalization
+ * @until //#initalization
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGridCollection.py
+ * @skipline #//initalization
+ * @until #//initalization
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * Xdmf supports the following collection types:
+ * NoCollectionType
+ * Spatial
+ * Temporal
+ */
+class XDMF_EXPORT XdmfGridCollectionType : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfGridCollectionType();
+
+ friend class XdmfGridCollection;
+ friend class XdmfGridTemplate;
+
+ // Supported XdmfGridCollectionTypes
+ static shared_ptr<const XdmfGridCollectionType> NoCollectionType();
+ static shared_ptr<const XdmfGridCollectionType> Spatial();
+ static shared_ptr<const XdmfGridCollectionType> Temporal();
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+protected:
+
+ /**
+ * Protected constructor for XdmfGridCollectionType. The constructor
+ * is protected because all collection types supported by Xdmf
+ * should be accessed through more specific static methods that
+ * construct XdmfGridCollectionType -
+ * i.e. XdmfGridCollectionType::Temporal().
+ *
+ * @param name the name of the XdmfGridCollectionType to construct.
+ */
+ XdmfGridCollectionType(const std::string & name);
+
+ static std::map<std::string, shared_ptr<const XdmfGridCollectionType>(*)()> mGridCollectionDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfGridCollectionType(const XdmfGridCollectionType &); // Not implemented.
+ void operator=(const XdmfGridCollectionType &); // Not implemented.
+
+ static shared_ptr<const XdmfGridCollectionType>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ std::string mName;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#define XDMF_GRID_COLLECTION_TYPE_SPATIAL 400
+#define XDMF_GRID_COLLECTION_TYPE_TEMPORAL 401
+#define XDMF_GRID_COLLECTION_TYPE_NO_COLLECTION_TYPE 402
+
+XDMF_EXPORT int XdmfGridCollectionTypeNoCollectionType();
+XDMF_EXPORT int XdmfGridCollectionTypeSpatial();
+XDMF_EXPORT int XdmfGridCollectionTypeTemporal();
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* XDMFGRIDCOLLECTIONTYPE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGridController.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2015 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfCurvilinearGrid.hpp"
+#include "XdmfError.hpp"
+#include "XdmfGrid.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfGridController.hpp"
+#include "XdmfReader.hpp"
+#include "XdmfRectilinearGrid.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfUnstructuredGrid.hpp"
+#include "string.h"
+#include <stdio.h>
+
+shared_ptr<XdmfGridController>
+XdmfGridController::New(const std::string & filePath,
+ const std::string & xmlPath)
+{
+ shared_ptr<XdmfGridController> p(new XdmfGridController(filePath,
+ xmlPath));
+ return p;
+}
+
+XdmfGridController::XdmfGridController(const std::string & filePath,
+ const std::string & xmlPath) :
+ mFilePath(filePath),
+ mXMLPath(xmlPath)
+{
+}
+
+XdmfGridController::XdmfGridController(const XdmfGridController& refController):
+ mFilePath(refController.getFilePath()),
+ mXMLPath(refController.getXMLPath())
+{
+}
+
+XdmfGridController::~XdmfGridController()
+{
+}
+
+const std::string XdmfGridController::ItemTag = "XGrid";
+
+std::string
+XdmfGridController::getFilePath() const
+{
+ return mFilePath;
+}
+
+std::string
+XdmfGridController::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::map<std::string, std::string>
+XdmfGridController::getItemProperties() const
+{
+ std::map<std::string, std::string> gridProperties;
+ gridProperties.insert(std::make_pair("File", mFilePath));
+ gridProperties.insert(std::make_pair("XPath", mXMLPath));
+ return gridProperties;
+}
+
+std::string
+XdmfGridController::getXMLPath() const
+{
+ return mXMLPath;
+}
+
+shared_ptr<XdmfGrid>
+XdmfGridController::read()
+{
+ shared_ptr<XdmfReader> gridReader = XdmfReader::New();
+ return shared_dynamic_cast<XdmfGrid>(gridReader->read(mFilePath, mXMLPath)[0]);
+}
+
+// C Wrappers
+
+XDMFGRIDCONTROLLER *
+XdmfGridControllerNew(char * filePath, char * xmlPath)
+{
+ try
+ {
+ XDMFGRIDCONTROLLER * returnController = NULL;
+ shared_ptr<XdmfGridController> generatedController = XdmfGridController::New(std::string(filePath), std::string(xmlPath));
+ returnController = (XDMFGRIDCONTROLLER *)((void *)((XdmfItem *)(new XdmfGridController(*generatedController.get()))));
+ generatedController.reset();
+ return returnController;
+ }
+ catch (...)
+ {
+ XDMFGRIDCONTROLLER * returnController = NULL;
+ shared_ptr<XdmfGridController> generatedController = XdmfGridController::New(std::string(filePath), std::string(xmlPath));
+ returnController = (XDMFGRIDCONTROLLER *)((void *)((XdmfItem *)(new XdmfGridController(*generatedController.get()))));
+ generatedController.reset();
+ return returnController;
+ }
+}
+
+char *
+XdmfGridControllerGetFilePath(XDMFGRIDCONTROLLER * controller)
+{
+ try
+ {
+ XdmfGridController referenceController = *(XdmfGridController *)(controller);
+ char * returnPointer = strdup(referenceController.getFilePath().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ XdmfGridController referenceController = *(XdmfGridController *)(controller);
+ char * returnPointer = strdup(referenceController.getFilePath().c_str());
+ return returnPointer;
+ }
+}
+
+char *
+XdmfGridControllerGetXMLPath(XDMFGRIDCONTROLLER * controller)
+{
+ try
+ {
+ XdmfGridController referenceController = *(XdmfGridController *)(controller);
+ char * returnPointer = strdup(referenceController.getXMLPath().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ XdmfGridController referenceController = *(XdmfGridController *)(controller);
+ char * returnPointer = strdup(referenceController.getXMLPath().c_str());
+ return returnPointer;
+ }
+}
+
+XDMFGRID *
+XdmfGridControllerRead(XDMFGRIDCONTROLLER * controller)
+{
+ try
+ {
+ XdmfGridController referenceController = *(XdmfGridController *)(controller);
+ shared_ptr<XdmfGrid> returnGrid = referenceController.read();
+ XDMFGRID * returnPointer = NULL;
+ if (shared_ptr<XdmfCurvilinearGrid> curvilinearGrid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(returnGrid))
+ {
+ returnPointer = (XDMFGRID *)((void *)((XdmfItem *)(new XdmfCurvilinearGrid(*curvilinearGrid.get()))));
+ }
+ else if (shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(returnGrid))
+ {
+ returnPointer = (XDMFGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*rectilinearGrid.get()))));
+ }
+ else if (shared_ptr<XdmfRegularGrid> regularGrid =
+ shared_dynamic_cast<XdmfRegularGrid>(returnGrid))
+ {
+ returnPointer = (XDMFGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*regularGrid.get()))));
+ }
+ else if (shared_ptr<XdmfGridCollection> collectionGrid =
+ shared_dynamic_cast<XdmfGridCollection>(returnGrid))
+ {
+ returnPointer = (XDMFGRID *)((void *)((XdmfItem *)(new XdmfGridCollection(*collectionGrid.get()))));
+ }
+ else if (shared_ptr<XdmfUnstructuredGrid> unstructuredGrid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(returnGrid))
+ {
+ returnPointer = (XDMFGRID *)((void *)((XdmfItem *)(new XdmfUnstructuredGrid(*unstructuredGrid.get()))));
+ }
+ return returnPointer;
+ }
+ catch (...)
+ {
+ return NULL;
+ }
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfGridController, XDMFGRIDCONTROLLER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfGridController.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2015 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGRIDCONTROLLER_HPP_
+#define XDMFGRIDCONTROLLER_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfGrid;
+
+// Includes
+#include <string>
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief Couples an XdmfGrid with a grid on a different XML file.
+ *
+ * Serves as an method to reduce memory usage by leaving part of
+ * the xdmf tree in file.
+ */
+class XDMF_EXPORT XdmfGridController : public virtual XdmfItem {
+
+public:
+
+ /**
+ * Creates a link to an xdmf tree in another file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGridController
+ * @until //#setGridController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGridController
+ * @until #//setGridController
+ *
+ * @param filePath
+ * @param xmlPath
+ *
+ * @return A reference to the external xdmf tree
+ */
+ static shared_ptr<XdmfGridController>
+ New(const std::string & filePath,
+ const std::string & xmlPath);
+
+ friend class XdmfWriter;
+ friend class XdmfGrid;
+
+ virtual ~XdmfGridController();
+
+ static const std::string ItemTag;
+
+ /**
+ * Gets the file path of the grid that this reference reads from.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGridController
+ * @until //#setGridController
+ * @skipline //#getFilePath
+ * @until //#getFilePath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGridController
+ * @until #//setGridController
+ * @skipline #//getFilePath
+ * @until #//getFilePath
+ *
+ * @return The file path.
+ */
+ std::string getFilePath() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ virtual std::string getItemTag() const;
+
+ /**
+ * Gets the XML path that refers to the base node in the reference file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGridController
+ * @until //#setGridController
+ * @skipline //#getXMLPath
+ * @until //#getXMLPath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGridController
+ * @until #//setGridController
+ * @skipline #//getXMLPath
+ * @until #//getXMLPath
+ *
+ * @return The XML path.
+ */
+ std::string getXMLPath() const;
+
+ /**
+ * Reads the grid that his controller references.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGridController
+ * @until //#setGridController
+ * @skipline //#controllerRead
+ * @until //#controllerRead
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGridController
+ * @until #//setGridController
+ * @skipline #//controllerRead
+ * @until #//controllerRead
+ *
+ * @return The grid read from the controller's stored location
+ */
+ virtual shared_ptr<XdmfGrid> read();
+
+ XdmfGridController(const XdmfGridController&);
+
+protected:
+
+ XdmfGridController(const std::string & filePath,
+ const std::string & xmlPath);
+
+ const std::string mFilePath;
+ const std::string mXMLPath;
+
+private:
+
+// XdmfGridController(const XdmfGridController&); // Not implemented.
+ void operator=(const XdmfGridController &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#ifndef XDMFGRIDCDEFINE
+#define XDMFGRIDCDEFINE
+struct XDMFGRID; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRID XDMFGRID;
+#endif
+
+struct XDMFGRIDCONTROLLER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRIDCONTROLLER XDMFGRIDCONTROLLER;
+
+XDMF_EXPORT XDMFGRIDCONTROLLER * XdmfGridControllerNew(char * filePath,
+ char * xmlPath);
+
+XDMF_EXPORT char * XdmfGridControllerGetFilePath(XDMFGRIDCONTROLLER * controller);
+
+XDMF_EXPORT char * XdmfGridControllerGetXMLPath(XDMFGRIDCONTROLLER * controller);
+
+XDMF_EXPORT XDMFGRID * XdmfGridControllerRead(XDMFGRIDCONTROLLER * controller);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfGridController, XDMFGRIDCONTROLLER, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFGRIDCONTROLLER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTemplate.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <sstream>
+#include <utility>
+#include "XdmfArray.hpp"
+#include "XdmfCurvilinearGrid.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfItemFactory.hpp"
+#include "XdmfReader.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfGridCollectionType.hpp"
+#include "XdmfGridTemplate.hpp"
+#include "XdmfRectilinearGrid.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfTemplate.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfError.hpp"
+#include "XdmfUnstructuredGrid.hpp"
+#include "XdmfVisitor.hpp"
+#include "XdmfWriter.hpp"
+
+#include "XdmfSystemUtils.hpp"
+
+#include <boost/tokenizer.hpp>
+
+#include <stdio.h>
+
+shared_ptr<XdmfGridTemplate>
+XdmfGridTemplate::New()
+{
+ shared_ptr<XdmfGridTemplate> p(new XdmfGridTemplate());
+ return p;
+}
+
+
+XdmfGridTemplate::XdmfGridTemplate() :
+ XdmfTemplate(),
+ XdmfGridCollection(),
+ mTimeCollection(XdmfArray::New())
+{
+ mTimeCollection->setName("Time Collection");
+}
+
+XdmfGridTemplate::XdmfGridTemplate(XdmfGridTemplate & refTemplate) :
+ XdmfTemplate(refTemplate),
+ XdmfGridCollection(refTemplate),
+ mTimeCollection(refTemplate.mTimeCollection)
+{
+}
+
+XdmfGridTemplate::~XdmfGridTemplate()
+{
+}
+
+const std::string XdmfGridTemplate::ItemTag = "Template";
+
+unsigned int
+XdmfGridTemplate::addStep()
+{
+ XdmfTemplate::addStep();
+ if (shared_dynamic_cast<XdmfGrid>(mBase)->getTime()) {
+ if (!mTimeCollection->isInitialized()) {
+ mTimeCollection->read();
+ }
+ mTimeCollection->pushBack(shared_dynamic_cast<XdmfGrid>(mBase)->getTime()->getValue());
+ }
+ return mCurrentStep;
+}
+
+std::map<std::string, std::string>
+XdmfGridTemplate::getItemProperties() const
+{
+ std::map<std::string, std::string> templateProperties = XdmfGridCollection::getItemProperties();
+
+ templateProperties["BaseType"] = "Grid";
+ return templateProperties;
+}
+
+std::string
+XdmfGridTemplate::getItemTag() const
+{
+ return ItemTag;
+}
+
+shared_ptr<XdmfArray>
+XdmfGridTemplate::getTimes()
+{
+ return mTimeCollection;
+}
+
+shared_ptr<XdmfGridCollection>
+XdmfGridTemplate::getGridCollection(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ this->clearStep();
+ this->setStep(index);
+ if (shared_ptr<XdmfGridCollection> grid =
+ shared_dynamic_cast<XdmfGridCollection>(mBase)) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get GridCollection from template without a base");
+ return shared_ptr<XdmfGridCollection>();
+ }
+}
+
+shared_ptr<const XdmfGridCollection>
+XdmfGridTemplate::getGridCollection(const unsigned int index) const
+{
+ if (shared_ptr<XdmfGridCollection> grid =
+ shared_dynamic_cast<XdmfGridCollection>(mBase)) {
+ if (index != mCurrentStep)
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: GridTemplates can not return a constant reference to its base on an index other than the currently loaded one.");
+ return shared_ptr<XdmfGridCollection>();
+ }
+ else
+ {
+ return grid;
+ }
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+}
+
+shared_ptr<XdmfGridCollection>
+XdmfGridTemplate::getGridCollection(const std::string & Name)
+{
+ if (mBase) {
+ if (shared_ptr<XdmfGridCollection> grid =
+ shared_dynamic_cast<XdmfGridCollection>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get GridCollection from template without a base");
+ return shared_ptr<XdmfGridCollection>();
+ }
+}
+
+shared_ptr<const XdmfGridCollection>
+XdmfGridTemplate::getGridCollection(const std::string & Name) const
+{
+ if (mBase) {
+ if (shared_ptr<XdmfGridCollection> grid =
+ shared_dynamic_cast<XdmfGridCollection>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfGridCollection>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get GridCollection from template without a base");
+ return shared_ptr<XdmfGridCollection>();
+ }
+}
+
+unsigned int
+XdmfGridTemplate::getNumberGridCollections() const
+{
+ if (shared_ptr<XdmfGridCollection> grid =
+ shared_dynamic_cast<XdmfGridCollection>(mBase)) {
+ return this->getNumberSteps();
+ }
+ else {
+ return 0;
+ }
+}
+
+void
+XdmfGridTemplate::insert(const shared_ptr<XdmfGridCollection> /*GridCollection*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to use insert to add an XdmfGridCollection to an XdmfGridTemplate. "
+ "Use addStep instead of insert to add to an XdmfGridTemplate");
+}
+
+void
+XdmfGridTemplate::removeGridCollection(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ if (shared_ptr<XdmfGridCollection> grid =
+ shared_dynamic_cast<XdmfGridCollection>(mBase)) {
+ this->removeStep(index);
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get GridCollection from template without a base");
+ }
+}
+
+void
+XdmfGridTemplate::removeGridCollection(const std::string & /*Name*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Removing Grids by name from XdmfGridTemplate is not supported");
+}
+
+shared_ptr<XdmfCurvilinearGrid>
+XdmfGridTemplate::getCurvilinearGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ this->clearStep();
+ this->setStep(index);
+ if (shared_ptr<XdmfCurvilinearGrid> grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(mBase)) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get CurvilinearGrid from template without a base");
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+}
+
+shared_ptr<const XdmfCurvilinearGrid>
+XdmfGridTemplate::getCurvilinearGrid(const unsigned int index) const
+{
+ if (shared_ptr<XdmfCurvilinearGrid> grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(mBase)) {
+ if (index != mCurrentStep)
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: GridTemplates can not return a constant reference to its base on an index other than the currently loaded one.");
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ else
+ {
+ return grid;
+ }
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+}
+
+shared_ptr<XdmfCurvilinearGrid>
+XdmfGridTemplate::getCurvilinearGrid(const std::string & Name)
+{
+ if (mBase) {
+ if (shared_ptr<XdmfCurvilinearGrid> grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get CurvilinearGrid from template without a base");
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+}
+
+shared_ptr<const XdmfCurvilinearGrid>
+XdmfGridTemplate::getCurvilinearGrid(const std::string & Name) const
+{
+ if (mBase) {
+ if (shared_ptr<XdmfCurvilinearGrid> grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get CurvilinearGrid from template without a base");
+ return shared_ptr<XdmfCurvilinearGrid>();
+ }
+}
+
+unsigned int
+XdmfGridTemplate::getNumberCurvilinearGrids() const
+{
+ if (shared_ptr<XdmfCurvilinearGrid> grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(mBase)) {
+ return this->getNumberSteps();
+ }
+ else {
+ return 0;
+ }
+}
+
+void
+XdmfGridTemplate::insert(const shared_ptr<XdmfCurvilinearGrid> /*CurvilinearGrid*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to use insert to add an XdmfCurvilinearGrid to an XdmfGridTemplate. "
+ "Use addStep instead of insert to add to an XdmfGridTemplate");
+}
+
+void
+XdmfGridTemplate::removeCurvilinearGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ if (shared_ptr<XdmfCurvilinearGrid> grid =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(mBase)) {
+ this->removeStep(index);
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get CurvilinearGrid from template without a base");
+ }
+}
+
+void
+XdmfGridTemplate::removeCurvilinearGrid(const std::string & /*Name*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Removing Grids by name from XdmfGridTemplate is not supported");
+}
+
+shared_ptr<XdmfRectilinearGrid>
+XdmfGridTemplate::getRectilinearGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ this->clearStep();
+ this->setStep(index);
+ if (shared_ptr<XdmfRectilinearGrid> grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(mBase)) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RectilinearGrid from template without a base");
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+}
+
+shared_ptr<const XdmfRectilinearGrid>
+XdmfGridTemplate::getRectilinearGrid(const unsigned int index) const
+{
+ if (shared_ptr<XdmfRectilinearGrid> grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(mBase)) {
+ if (index != mCurrentStep)
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: GridTemplates can not return a constant reference to its base on an index other than the currently loaded one.");
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ else
+ {
+ return grid;
+ }
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+}
+
+shared_ptr<XdmfRectilinearGrid>
+XdmfGridTemplate::getRectilinearGrid(const std::string & Name)
+{
+ if (mBase) {
+ if (shared_ptr<XdmfRectilinearGrid> grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RectilinearGrid from template without a base");
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+}
+
+shared_ptr<const XdmfRectilinearGrid>
+XdmfGridTemplate::getRectilinearGrid(const std::string & Name) const
+{
+ if (mBase) {
+ if (shared_ptr<XdmfRectilinearGrid> grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RectilinearGrid from template without a base");
+ return shared_ptr<XdmfRectilinearGrid>();
+ }
+}
+
+unsigned int
+XdmfGridTemplate::getNumberRectilinearGrids() const
+{
+ if (shared_ptr<XdmfRectilinearGrid> grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(mBase)) {
+ return this->getNumberSteps();
+ }
+ else {
+ return 0;
+ }
+}
+
+void
+XdmfGridTemplate::insert(const shared_ptr<XdmfRectilinearGrid> /*RectilinearGrid*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to use insert to add a XdmfRectilinearGrid to an XdmfGridTemplate."
+ "Use addStep instead of insert to add to an XdmfGridTemplate");
+}
+
+void
+XdmfGridTemplate::removeRectilinearGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ if (shared_ptr<XdmfRectilinearGrid> grid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(mBase)) {
+ this->removeStep(index);
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RectilinearGrid from template without a base");
+ }
+}
+
+void
+XdmfGridTemplate::removeRectilinearGrid(const std::string & /*Name*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Removing Grids by name from XdmfGridTemplate is not supported");
+}
+
+shared_ptr<XdmfRegularGrid>
+XdmfGridTemplate::getRegularGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ this->clearStep();
+ this->setStep(index);
+ if (shared_ptr<XdmfRegularGrid> grid =
+ shared_dynamic_cast<XdmfRegularGrid>(mBase)) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RegularGrid from template without a base");
+ return shared_ptr<XdmfRegularGrid>();
+ }
+}
+
+shared_ptr<const XdmfRegularGrid>
+XdmfGridTemplate::getRegularGrid(const unsigned int index) const
+{
+ if (shared_ptr<XdmfRegularGrid> grid =
+ shared_dynamic_cast<XdmfRegularGrid>(mBase)) {
+ if (index != mCurrentStep)
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: GridTemplates can not return a constant reference to its base on an index other than the currently loaded one.");
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ else
+ {
+ return grid;
+ }
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+}
+
+shared_ptr<XdmfRegularGrid>
+XdmfGridTemplate::getRegularGrid(const std::string & Name)
+{
+ if (mBase) {
+ if (shared_ptr<XdmfRegularGrid> grid =
+ shared_dynamic_cast<XdmfRegularGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RegularGrid from template without a base");
+ return shared_ptr<XdmfRegularGrid>();
+ }
+}
+
+shared_ptr<const XdmfRegularGrid>
+XdmfGridTemplate::getRegularGrid(const std::string & Name) const
+{
+ if (mBase) {
+ if (shared_ptr<XdmfRegularGrid> grid =
+ shared_dynamic_cast<XdmfRegularGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfRegularGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RegularGrid from template without a base");
+ return shared_ptr<XdmfRegularGrid>();
+ }
+}
+
+unsigned int
+XdmfGridTemplate::getNumberRegularGrids() const
+{
+ if (shared_ptr<XdmfRegularGrid> grid =
+ shared_dynamic_cast<XdmfRegularGrid>(mBase)) {
+ return this->getNumberSteps();
+ }
+ else {
+ return 0;
+ }
+}
+
+void
+XdmfGridTemplate::insert(const shared_ptr<XdmfRegularGrid> /*RegularGrid*/)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to use insert to add an XdmfRegularGrid to an XdmfGridTemplate."
+ "Use addStep instead of insert to add to an XdmfGridTemplate");
+}
+
+void
+XdmfGridTemplate::removeRegularGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ if (shared_ptr<XdmfRegularGrid> grid =
+ shared_dynamic_cast<XdmfRegularGrid>(mBase)) {
+ this->removeStep(index);
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get RegularGrid from template without a base");
+ }
+}
+
+void
+XdmfGridTemplate::removeRegularGrid(const std::string & Name)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Removing Grids by name from XdmfGridTemplate is not supported");
+}
+
+shared_ptr<XdmfUnstructuredGrid>
+XdmfGridTemplate::getUnstructuredGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ this->clearStep();
+ this->setStep(index);
+ if (shared_ptr<XdmfUnstructuredGrid> grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(mBase)) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get UnstructuredGrid from template without a base");
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+}
+
+shared_ptr<const XdmfUnstructuredGrid>
+XdmfGridTemplate::getUnstructuredGrid(const unsigned int index) const
+{
+ if (shared_ptr<XdmfUnstructuredGrid> grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(mBase)) {
+ if (index != mCurrentStep)
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: GridTemplates can not return a constant reference to its base on an index other than the currently loaded one.");
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ else
+ {
+ return grid;
+ }
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+}
+
+shared_ptr<XdmfUnstructuredGrid>
+XdmfGridTemplate::getUnstructuredGrid(const std::string & Name)
+{
+ if (mBase) {
+ if (shared_ptr<XdmfUnstructuredGrid> grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get UnstructuredGrid from template without a base");
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+}
+
+shared_ptr<const XdmfUnstructuredGrid>
+XdmfGridTemplate::getUnstructuredGrid(const std::string & Name) const
+{
+ if (mBase) {
+ if (shared_ptr<XdmfUnstructuredGrid> grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(mBase)) {
+ if (grid->getName().compare(Name) == 0) {
+ return grid;
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ }
+ else {
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get UnstructuredGrid from template without a base");
+ return shared_ptr<XdmfUnstructuredGrid>();
+ }
+}
+
+unsigned int
+XdmfGridTemplate::getNumberUnstructuredGrids() const
+{
+ if (shared_ptr<XdmfUnstructuredGrid> grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(mBase)) {
+ return this->getNumberSteps();
+ }
+ else {
+ return 0;
+ }
+}
+
+
+void
+XdmfGridTemplate::insert(const shared_ptr<XdmfUnstructuredGrid> UnstructuredGrid)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to use insert to add an XdmfUnstructuredGrid to an XdmfGridTemplate."
+ "Use addStep instead of insert to add to an XdmfGridTemplate");
+}
+
+void
+XdmfGridTemplate::removeUnstructuredGrid(const unsigned int index)
+{
+ if (mBase) {
+ if (index < getNumberSteps()) {
+ if (shared_ptr<XdmfUnstructuredGrid> grid =
+ shared_dynamic_cast<XdmfUnstructuredGrid>(mBase)) {
+ this->removeStep(index);
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Attempting to get UnstructuredGrid from template without a base");
+ }
+}
+
+
+void
+XdmfGridTemplate::removeUnstructuredGrid(const std::string & Name)
+{
+ XdmfError::message(XdmfError::FATAL, "Error: Removing Grids by name from XdmfGridTemplate is not supported");
+}
+
+void
+XdmfGridTemplate::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ // We are overrriding the populate item of the template and grid collection here
+ // The template functions internally different from either.
+
+ this->setType(XdmfGridCollectionType::New(itemProperties));
+
+ // The first child item is the base
+ mBase = childItems[0];
+ mCurrentStep = 0;
+
+ if (childItems.size() > 1) {
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin() + 1;
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ if (array->getName().compare("Data Description") == 0) {
+ // Split description into substrings based on the " character
+
+ if (array->getNumberHeavyDataControllers() > 0 && !mHeavyWriter) {
+ mHeavyWriter = reader->generateHeavyDataWriter(array->getHeavyDataController(0)->getName(), array->getHeavyDataController(0)->getFilePath());
+ }
+
+ array->read();
+
+ // If a character array, create std::string version? TODO
+ std::string descriptionString;
+ if (array->getArrayType() == XdmfArrayType::Int8())
+ {
+ descriptionString = std::string((char *)array->getValuesInternal());
+ }
+ else if (array->getArrayType() == XdmfArrayType::String())
+ {
+ descriptionString = array->getValue<std::string>(0);
+ }
+
+ size_t index = descriptionString.find_first_of("\"");
+ size_t previousIndex = 0;
+
+ if (index != std::string::npos) {
+ // Removing the prepended "
+ previousIndex = index + 1;
+ index = descriptionString.find_first_of("\"", previousIndex);
+ }
+
+ while (index != std::string::npos) {
+ std::string type = descriptionString.substr(previousIndex, index - previousIndex);
+ mDataTypes.push_back(type);
+ previousIndex = index + 1;
+ index = descriptionString.find_first_of("\"", previousIndex);
+ if (index - previousIndex > 0) {
+ std::string description;
+ description = descriptionString.substr(previousIndex, index - previousIndex);
+ mDataDescriptions.push_back(description);
+ // create controllers here based on the type/description?
+ // Is array type already filled?
+ // Potentially call "fillControllers" after populating?
+ if (index != std::string::npos) {
+ previousIndex = index + 1;
+ index = descriptionString.find_first_of("\"", previousIndex);
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Type without a description in XdmfTemplate::populateItem");
+ }
+ }
+ }
+ else if (array->getName().compare("Time Collection") == 0) {
+ mTimeCollection = array;
+ }
+ else {
+ mTrackedArrays.push_back(array.get());
+ mTrackedArrayDims.push_back(array->getDimensions());
+ mTrackedArrayTypes.push_back(array->getArrayType());
+ }
+ }
+ }
+ }
+ mDataControllers.resize(mDataTypes.size());
+ if (!mItemFactory) {
+ mItemFactory = XdmfItemFactory::New();
+ }
+ std::map<std::string, std::string> populateProperties;
+ if (mHeavyWriter) {
+ // The heavy writer provides the XMLDir, which is used to get full paths for the controllers
+ // It is assumed that the files that the controllers reference are in the same directory
+ // as the file that the writer references
+ std::string filepath = XdmfSystemUtils::getRealPath(mHeavyWriter->getFilePath());
+ size_t index = filepath.find_last_of("/\\");
+ filepath = filepath.substr(0, index + 1);
+ populateProperties["XMLDir"] = filepath;
+ }
+ for (unsigned int i = 0; i < mDataDescriptions.size(); ++i) {
+ populateProperties["Content"] = mDataDescriptions[i];
+ std::vector<shared_ptr<XdmfHeavyDataController> > readControllers =
+ reader->generateHeavyDataControllers(populateProperties, mTrackedArrayDims[i % mTrackedArrays.size()], mTrackedArrayTypes[i % mTrackedArrays.size()], mDataTypes[i]);
+ if (readControllers.size() > 0) {
+ // Heavy data controllers reference the data
+ for (unsigned int j = 0; j < readControllers.size(); ++j) {
+ mDataControllers[i].push_back(readControllers[j]);
+ }
+ }
+ }
+ // Compare the first set of controllers to the size of the first array
+ unsigned int controllerTotal = 0;
+ for (unsigned int i = 0; i < mDataControllers[0].size(); ++i)
+ {
+ controllerTotal += mDataControllers[0][i]->getSize();
+ }
+ // If the array is smaller, set the writer to append.
+ if (controllerTotal > mTrackedArrays[0]->getSize())
+ {
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Append);
+ mNumSteps = controllerTotal / mTrackedArrays[0]->getSize();
+ }
+ else {
+ mNumSteps = mDataControllers.size() / mTrackedArrays.size();
+ }
+}
+
+void
+XdmfGridTemplate::removeStep(unsigned int stepId)
+{
+ if (stepId < this->getNumberSteps()) {
+ XdmfTemplate::removeStep(stepId);
+ mTimeCollection->erase(stepId);
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfGridTemplate::setBase(shared_ptr<XdmfItem> newBase)
+{
+ if (shared_ptr<XdmfGrid> grid = shared_dynamic_cast<XdmfGrid>(newBase)) {
+ XdmfTemplate::setBase(newBase);
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: XdmfGridTemplate::setBase,"
+ " attempting to set a Base that is not grid type.");
+ }
+}
+
+void
+XdmfGridTemplate::setStep(unsigned int stepId)
+{
+ XdmfTemplate::setStep(stepId);
+ if (mTimeCollection->getSize() >= stepId) {
+ if (!mTimeCollection->isInitialized()) {
+ mTimeCollection->read();
+ }
+ if (shared_dynamic_cast<XdmfGrid>(mBase)->getTime()) {
+ shared_dynamic_cast<XdmfGrid>(mBase)->getTime()->setValue(mTimeCollection->getValue<double>(stepId));
+ }
+ else {
+ shared_dynamic_cast<XdmfGrid>(mBase)->setTime(XdmfTime::New(mTimeCollection->getValue<double>(stepId)));
+ }
+ }
+}
+
+void
+XdmfGridTemplate::setStep(shared_ptr<XdmfTime> time)
+{
+ if (mTimeCollection->getSize() > 0)
+ {
+ if (!mTimeCollection->isInitialized()) {
+ mTimeCollection->read();
+ }
+ unsigned int index = 0;
+ while (index < mTimeCollection->getSize() &&
+ time->getValue() != mTimeCollection->getValue<double>(index))
+ {
+ ++index;
+ }
+ if (index < mTimeCollection->getSize())
+ {
+ this->setStep(index);
+ }
+ }
+}
+
+void
+XdmfGridTemplate::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ // We are only using the template traverse
+ // since the grid data is only held in the Base
+ if (mTimeCollection->getSize() > 0)
+ {
+ this->setType(XdmfGridCollectionType::Temporal());
+ }
+ else
+ {
+ this->setType(XdmfGridCollectionType::Spatial());
+ }
+ XdmfTemplate::traverse(visitor);
+ mTimeCollection->accept(visitor);
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfGridTemplate, XDMFGRIDTEMPLATE)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTemplate.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFGRIDTEMPLATE_HPP_
+#define XDMFGRIDTEMPLATE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfItemFactory.hpp"
+#include "XdmfTemplate.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+
+/**
+ * @brief Defines a template that can be filled with multiple sets of data.
+ *
+ * An XdmfTemplate defines a structure. The arrays within that structure
+ * are stored if they are not initialized when the structure is first set.
+ * Steps can then be added and references to heavy data are produced and
+ * stored for later retrieval.
+ *
+ * This effectively lets an object have several variations with different
+ * contained data.
+ */
+class XDMF_EXPORT XdmfGridTemplate : public XdmfTemplate,
+ public XdmfGridCollection {
+
+public:
+
+ /**
+ * Creates a new instance of the XdmfTemplate object
+ *
+ * @return A constructed XdmfTemplate object.
+ */
+ static shared_ptr<XdmfGridTemplate> New();
+
+ virtual ~XdmfGridTemplate();
+
+ LOKI_DEFINE_VISITABLE(XdmfGridTemplate, XdmfGrid);
+ static const std::string ItemTag;
+
+ /**
+ * Writes all tracked arrays to heavy data via the provided
+ * heavy data writer then stores the heavy data descriptions.
+ *
+ * @return The ID of the step that was added
+ */
+ virtual unsigned int addStep();
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ using XdmfGrid::insert;
+
+ // Overriding the parent versions so that all of these reference the Base item
+ // instead of the template
+
+ virtual shared_ptr<XdmfArray> getTimes();
+
+ virtual shared_ptr<XdmfGridCollection> getGridCollection(const unsigned int index);
+
+ virtual shared_ptr<const XdmfGridCollection> getGridCollection(const unsigned int index) const;
+
+ virtual shared_ptr<XdmfGridCollection> getGridCollection(const std::string & Name);
+
+ virtual shared_ptr<const XdmfGridCollection> getGridCollection(const std::string & Name) const;
+
+ virtual unsigned int getNumberGridCollections() const;
+
+ virtual void insert(const shared_ptr<XdmfGridCollection> GridCollection);
+
+ virtual void removeGridCollection(const unsigned int index);
+
+ virtual void removeGridCollection(const std::string & Name);
+
+ virtual shared_ptr<XdmfCurvilinearGrid> getCurvilinearGrid(const unsigned int index);
+
+ virtual shared_ptr<const XdmfCurvilinearGrid> getCurvilinearGrid(const unsigned int index) const;
+
+ virtual shared_ptr<XdmfCurvilinearGrid> getCurvilinearGrid(const std::string & Name);
+
+ virtual shared_ptr<const XdmfCurvilinearGrid> getCurvilinearGrid(const std::string & Name) const;
+
+ virtual unsigned int getNumberCurvilinearGrids() const;
+
+ virtual void insert(const shared_ptr<XdmfCurvilinearGrid> CurvilinearGrid);
+
+ virtual void removeCurvilinearGrid(const unsigned int index);
+
+ virtual void removeCurvilinearGrid(const std::string & Name);
+
+ virtual shared_ptr<XdmfRectilinearGrid> getRectilinearGrid(const unsigned int index);
+
+ virtual shared_ptr<const XdmfRectilinearGrid> getRectilinearGrid(const unsigned int index) const;
+
+ virtual shared_ptr<XdmfRectilinearGrid> getRectilinearGrid(const std::string & Name);
+
+ virtual shared_ptr<const XdmfRectilinearGrid> getRectilinearGrid(const std::string & Name) const;
+
+ virtual unsigned int getNumberRectilinearGrids() const;
+
+ virtual void insert(const shared_ptr<XdmfRectilinearGrid> RectilinearGrid);
+
+ virtual void removeRectilinearGrid(const unsigned int index);
+
+ virtual void removeRectilinearGrid(const std::string & Name);
+
+ virtual shared_ptr<XdmfRegularGrid> getRegularGrid(const unsigned int index);
+
+ virtual shared_ptr<const XdmfRegularGrid> getRegularGrid(const unsigned int index) const;
+
+ virtual shared_ptr<XdmfRegularGrid> getRegularGrid(const std::string & Name);
+
+ virtual shared_ptr<const XdmfRegularGrid> getRegularGrid(const std::string & Name) const;
+
+ virtual unsigned int getNumberRegularGrids() const;
+
+ virtual void insert(const shared_ptr<XdmfRegularGrid> RegularGrid);
+
+ virtual void removeRegularGrid(const unsigned int index);
+
+ virtual void removeRegularGrid(const std::string & Name);
+
+ virtual shared_ptr<XdmfUnstructuredGrid> getUnstructuredGrid(const unsigned int index);
+
+ virtual shared_ptr<const XdmfUnstructuredGrid> getUnstructuredGrid(const unsigned int index) const;
+
+ virtual shared_ptr<XdmfUnstructuredGrid> getUnstructuredGrid(const std::string & Name);
+
+ virtual shared_ptr<const XdmfUnstructuredGrid> getUnstructuredGrid(const std::string & Name) const;
+
+ virtual unsigned int getNumberUnstructuredGrids() const;
+
+ virtual void insert(const shared_ptr<XdmfUnstructuredGrid> UnstructuredGrid);
+
+ virtual void removeUnstructuredGrid(const unsigned int index);
+
+ virtual void removeUnstructuredGrid(const std::string & Name);
+
+ /**
+ *
+ */
+ virtual void removeStep(unsigned int stepId);
+
+ virtual void setBase(shared_ptr<XdmfItem> newBase);
+
+ /**
+ * Reads in the heavy data associated with the provided step id.
+ *
+ * @param stepId The id of the step whose heavy data
+ * is to be read in from file
+ */
+ void setStep(unsigned int stepId);
+
+ void setStep(shared_ptr<XdmfTime> time);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfGridTemplate(XdmfGridTemplate &);
+
+protected:
+
+ XdmfGridTemplate();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+ shared_ptr<XdmfArray> mTimeCollection;
+
+private:
+
+ XdmfGridTemplate(const XdmfGridTemplate &); // Not implemented.
+ void operator=(const XdmfGridTemplate &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFGRIDTEMPLATE; // Simply as a typedef to ensure correct typing
+typedef struct XDMFGRIDTEMPLATE XDMFGRIDTEMPLATE;
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfGridTemplate, XDMFGRIDTEMPLATE, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* XDMFGRIDTEMPLATE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfItemFactory.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <cctype>
+#include <boost/tokenizer.hpp>
+#include "XdmfAttribute.hpp"
+#include "XdmfCurvilinearGrid.hpp"
+#include "XdmfDomain.hpp"
+#include "XdmfError.hpp"
+#include "XdmfFunction.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfGeometryType.hpp"
+#include "XdmfGraph.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfGridTemplate.hpp"
+#include "XdmfInformation.hpp"
+#include "XdmfItemFactory.hpp"
+#include "XdmfAggregate.hpp"
+#include "XdmfMap.hpp"
+#include "XdmfRectilinearGrid.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfSet.hpp"
+#include "XdmfSparseMatrix.hpp"
+#include "XdmfTemplate.hpp"
+#include "XdmfTime.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfUnstructuredGrid.hpp"
+
+shared_ptr<XdmfItemFactory>
+XdmfItemFactory::New()
+{
+ shared_ptr<XdmfItemFactory> p(new XdmfItemFactory());
+ return p;
+}
+
+XdmfItemFactory::XdmfItemFactory()
+{
+}
+
+XdmfItemFactory::~XdmfItemFactory()
+{
+}
+
+shared_ptr<XdmfItem>
+XdmfItemFactory::createItem(const std::string & itemTag,
+ const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems) const
+{
+#ifdef XDMF_BUILD_DSM
+ shared_ptr<XdmfItem> newItem =
+ XdmfDSMItemFactory::createItem(itemTag, itemProperties, childItems);
+#else
+ shared_ptr<XdmfItem> newItem =
+ XdmfCoreItemFactory::createItem(itemTag, itemProperties, childItems);
+#endif
+
+ if(newItem) {
+ return newItem;
+ }
+
+ if(itemTag.compare(XdmfAttribute::ItemTag) == 0) {
+ return XdmfAttribute::New();
+ }
+ else if(itemTag.compare(XdmfAggregate::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("ConstructedType");
+ std::string arraySubType;
+ if(type == itemProperties.end()) {
+ // If no type is specified an array is generated
+ arraySubType = XdmfArray::ItemTag;
+ }
+ else {
+ arraySubType = type->second;
+ }
+ std::vector<shared_ptr<XdmfItem> > newArrayChildren;
+ shared_ptr<XdmfItem> createdItem = createItem(arraySubType,
+ itemProperties,
+ newArrayChildren);
+
+ shared_ptr<XdmfArray> returnArray = shared_dynamic_cast<XdmfArray>(createdItem);
+
+ shared_ptr<XdmfAggregate> returnAggregate = XdmfAggregate::New();
+
+ bool placeholderFound = false;
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ if (!placeholderFound) {
+ placeholderFound = true;
+ }
+ else {
+ returnAggregate->insert(array);
+ }
+ }
+ }
+
+ returnArray->setReference(returnAggregate);
+ returnArray->setReadMode(XdmfArray::Reference);
+
+ return returnArray;
+ }
+ else if(itemTag.compare(XdmfDomain::ItemTag) == 0) {
+ return XdmfDomain::New();
+ }
+ else if(itemTag.compare(XdmfGeometry::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("GeometryType");
+ }
+
+ if(type != itemProperties.end()) {
+ const std::string & typeVal = type->second;
+ if(typeVal.compare("ORIGIN_DXDY") == 0 ||
+ typeVal.compare("ORIGIN_DXDYDZ") == 0 ||
+ typeVal.compare("ORIGIN_DISPLACEMENT") == 0) {
+ shared_ptr<XdmfArray> origin = shared_ptr<XdmfArray>();
+ shared_ptr<XdmfArray> brickSize = shared_ptr<XdmfArray>();
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array =
+ shared_dynamic_cast<XdmfArray>(*iter)) {
+ if(!origin) {
+ origin = array;
+ }
+ else if(!brickSize) {
+ brickSize = array;
+ break;
+ }
+ }
+ }
+ if(origin && brickSize) {
+ return XdmfRegularGrid::New(brickSize,
+ shared_ptr<XdmfArray>(),
+ origin);
+ }
+ return shared_ptr<XdmfItem>();
+ }
+ else if(typeVal.compare("VXVY") == 0 ||
+ typeVal.compare("VXVYVZ") == 0 ||
+ typeVal.compare("VECTORED") == 0) {
+ std::vector<shared_ptr<XdmfArray> > coordinateValues;
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array =
+ shared_dynamic_cast<XdmfArray>(*iter)) {
+ coordinateValues.push_back(array);
+ }
+ }
+ return shared_dynamic_cast<XdmfItem>(XdmfRectilinearGrid::New(coordinateValues));
+ }
+ }
+ return XdmfGeometry::New();
+ }
+ else if(itemTag.compare(XdmfGraph::ItemTag) == 0) {
+ return XdmfGraph::New(0);
+ }
+ else if(itemTag.compare(XdmfGrid::ItemTag) == 0) {
+ // For backwards compatibility with the old format, this tag can
+ // correspond to multiple XdmfItems.
+ std::map<std::string, std::string>::const_iterator gridType =
+ itemProperties.find("GridType");
+ if(gridType != itemProperties.end() &&
+ gridType->second.compare("Collection") == 0) {
+ return XdmfGridCollection::New();
+ }
+ else {
+ // Find out what kind of grid we have
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfCurvilinearGrid> curvilinear =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(*iter)) {
+ return XdmfCurvilinearGrid::New(0, 0);
+ }
+ else if(shared_ptr<XdmfRegularGrid> regularGrid =
+ shared_dynamic_cast<XdmfRegularGrid>(*iter)) {
+ return XdmfRegularGrid::New(0, 0, 0, 0, 0, 0);
+ }
+ else if(shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
+ std::vector<shared_ptr<XdmfArray> > coordinateValues;
+ return XdmfRectilinearGrid::New(coordinateValues);
+ }
+ }
+ return XdmfUnstructuredGrid::New();
+ }
+ }
+ else if(itemTag.compare(XdmfGridController::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator filename =
+ itemProperties.find("File");
+ std::map<std::string, std::string>::const_iterator xpath =
+ itemProperties.find("XPath");
+ return XdmfGridController::New(filename->second, xpath->second);
+ }
+ else if(itemTag.compare(XdmfInformation::ItemTag) == 0) {
+ return XdmfInformation::New();
+ }
+ else if(itemTag.compare(XdmfMap::ItemTag) == 0) {
+ return XdmfMap::New();
+ }
+ else if(itemTag.compare(XdmfSet::ItemTag) == 0) {
+ return XdmfSet::New();
+ }
+ else if(itemTag.compare(XdmfSparseMatrix::ItemTag) == 0) {
+ return XdmfSparseMatrix::New(0, 0);
+ }
+ else if (itemTag.compare(XdmfTemplate::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("BaseType");
+ if(type == itemProperties.end()) {
+ return XdmfTemplate::New();
+ }
+ else {
+ if (type->second.compare("Grid") == 0) {
+ return XdmfGridTemplate::New();
+ }
+ else {
+ return XdmfTemplate::New();
+ }
+ }
+ return XdmfTemplate::New();
+ }
+ else if(itemTag.compare(XdmfTime::ItemTag) == 0) {
+ return XdmfTime::New();
+ }
+ else if(itemTag.compare(XdmfTopology::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("TopologyType");
+ }
+
+ if(type != itemProperties.end()) {
+ std::string typeVal = type->second;
+ std::transform(typeVal.begin(),
+ typeVal.end(),
+ typeVal.begin(),
+ (int(*)(int))toupper);
+ if(typeVal.compare("2DCORECTMESH") == 0 ||
+ typeVal.compare("3DCORECTMESH") == 0 ||
+ typeVal.compare("CORECTMESH") == 0 ||
+ typeVal.compare("2DSMESH") == 0 ||
+ typeVal.compare("3DSMESH") == 0 ||
+ typeVal.compare("SMESH") == 0) {
+ shared_ptr<XdmfArray> dimensionsArray = XdmfArray::New();
+ std::string dimensionsString = "";
+ std::map<std::string, std::string>::const_iterator dimensions =
+ itemProperties.find("Dimensions");
+ if(dimensions != itemProperties.end()) {
+ dimensionsString = dimensions->second;
+ }
+ boost::tokenizer<> tokens(dimensionsString);
+ for(boost::tokenizer<>::const_iterator iter = tokens.begin();
+ iter != tokens.end();
+ ++iter) {
+ dimensionsArray->pushBack<unsigned int>(atoi((*iter).c_str()));
+ }
+ if(typeVal.compare("2DCORECTMESH") == 0 ||
+ typeVal.compare("3DCORECTMESH") == 0 ||
+ typeVal.compare("CORECTMESH") == 0) {
+ return XdmfRegularGrid::New(shared_ptr<XdmfArray>(),
+ dimensionsArray,
+ shared_ptr<XdmfArray>());
+ }
+ else {
+ return XdmfCurvilinearGrid::New(dimensionsArray);
+ }
+ }
+ else if(typeVal.compare("2DRECTMESH") == 0 ||
+ typeVal.compare("3DRECTMESH") == 0 ||
+ typeVal.compare("RECTMESH") == 0) {
+ std::vector<shared_ptr<XdmfArray> > coordinateValues;
+ return XdmfRectilinearGrid::New(coordinateValues);
+ }
+
+ }
+ return XdmfTopology::New();
+ }
+ return shared_ptr<XdmfItem>();
+}
+
+bool
+XdmfItemFactory::isArrayTag(char * tag) const
+{
+#ifdef XDMF_BUILD_DSM
+ if (XdmfDSMItemFactory::isArrayTag(tag))
+ {
+ return true;
+ }
+#else
+ if (XdmfCoreItemFactory::isArrayTag(tag))
+ {
+ return true;
+ }
+#endif
+ else if (XdmfAggregate::ItemTag.compare(tag) == 0) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+XdmfItem *
+XdmfItemFactory::DuplicatePointer(shared_ptr<XdmfItem> original) const
+{
+#ifdef XDMF_BUILD_DSM
+ XdmfItem * returnPointer = XdmfDSMItemFactory::DuplicatePointer(original);
+#else
+ XdmfItem * returnPointer = XdmfCoreItemFactory::DuplicatePointer(original);
+#endif
+
+ if (returnPointer) {
+ return returnPointer;
+ }
+ else {
+ if (original->getItemTag().compare(XdmfTime::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfTime(*((XdmfTime *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfAttribute::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfAttribute(*((XdmfAttribute *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfDomain::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfDomain(*(shared_dynamic_cast<XdmfDomain>(original).get())));
+ }
+ else if (original->getItemTag().compare(XdmfTopology::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfTopology(*((XdmfTopology *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfGeometry::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfGeometry(*((XdmfGeometry *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfGraph::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfGraph(*((XdmfGraph *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfSet::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfSet(*((XdmfSet *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfMap::ItemTag) == 0) {
+ return (XdmfItem *)(new XdmfMap(*((XdmfMap *)original.get())));
+ }
+ else if (original->getItemTag().compare(XdmfGrid::ItemTag) == 0) {
+ if (shared_ptr<XdmfGridCollection> collection =
+ shared_dynamic_cast<XdmfGridCollection>(original)) {
+ return (XdmfItem *)(new XdmfGridCollection(*(shared_dynamic_cast<XdmfGridCollection>(original).get())));
+ }
+ else if (shared_ptr<XdmfCurvilinearGrid> curvilinear =
+ shared_dynamic_cast<XdmfCurvilinearGrid>(original)) {
+ return (XdmfItem *)(new XdmfCurvilinearGrid(*(shared_dynamic_cast<XdmfCurvilinearGrid>(original).get())));
+ }
+ else if(shared_ptr<XdmfRegularGrid> regularGrid =
+ shared_dynamic_cast<XdmfRegularGrid>(original)) {
+ return (XdmfItem *)(new XdmfRegularGrid(*(shared_dynamic_cast<XdmfRegularGrid>(original).get())));
+ }
+ else if(shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(original)) {
+ return (XdmfItem *)(new XdmfRectilinearGrid(*(shared_dynamic_cast<XdmfRectilinearGrid>(original).get())));
+ }
+ return (XdmfItem *)(new XdmfUnstructuredGrid(*(shared_dynamic_cast<XdmfUnstructuredGrid>(original).get())));
+ }
+ }
+ return NULL;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfItemFactory.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFITEMFACTORY_HPP_
+#define XDMFITEMFACTORY_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfCoreItemFactory.hpp"
+#ifdef XDMF_BUILD_DSM
+ #include "XdmfDSMItemFactory.hpp"
+#endif
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfItem;
+
+// Includes
+#include "Xdmf.hpp"
+#include "XdmfCoreItemFactory.hpp"
+
+/**
+ * @brief Factory for constructing XdmfItems from their ItemTag and
+ * ItemProperties.
+ */
+#ifdef XDMF_BUILD_DSM
+class XDMF_EXPORT XdmfItemFactory : public XdmfDSMItemFactory {
+#else
+class XDMF_EXPORT XdmfItemFactory : public XdmfCoreItemFactory {
+#endif
+
+public:
+
+ /**
+ * Create a new XdmfItemFactory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfItemFactory.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleItemFactory.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfItemFactory.
+ */
+ static shared_ptr<XdmfItemFactory> New();
+
+ virtual ~XdmfItemFactory();
+
+ virtual shared_ptr<XdmfItem>
+ createItem(const std::string & itemTag,
+ const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems) const;
+
+ virtual bool isArrayTag(char * tag) const;
+
+ virtual XdmfItem *
+ DuplicatePointer(shared_ptr<XdmfItem> original) const;
+
+protected:
+
+ XdmfItemFactory();
+
+private:
+
+ XdmfItemFactory(const XdmfItemFactory &); // Not implemented.
+ void operator=(const XdmfItemFactory &); // Not implemented.
+
+};
+
+
+#endif
+
+#endif /* XDMFITEMFACTORY_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfMap.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include <string.h>
+#include "XdmfAttribute.hpp"
+#include "XdmfError.hpp"
+#include "XdmfGridCollection.hpp"
+#include "XdmfGridCollectionType.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfMap.hpp"
+#include "XdmfWriter.hpp"
+
+shared_ptr<XdmfMap>
+XdmfMap::New()
+{
+ shared_ptr<XdmfMap> p(new XdmfMap());
+ return p;
+}
+
+std::vector<shared_ptr<XdmfMap> >
+XdmfMap::New(const std::vector<shared_ptr<XdmfAttribute> > & globalNodeIds)
+{
+ // globalNodeId | taskId | localNodeId at taskId
+ std::map<node_id, std::map<task_id, node_id> > globalNodeIdMap;
+
+ // fill globalNodeIdMap using globalNodeIds
+ std::vector<bool> releaseGlobalNodeIds(globalNodeIds.size(), false);
+ for(unsigned int i=0; i<globalNodeIds.size(); ++i) {
+ const shared_ptr<XdmfAttribute> currGlobalNodeIds = globalNodeIds[i];
+ if(!currGlobalNodeIds->isInitialized()) {
+ currGlobalNodeIds->read();
+ releaseGlobalNodeIds[i] = true;
+ }
+ for(unsigned int j=0; j<currGlobalNodeIds->getSize(); ++j) {
+ const node_id currGlobalNodeId = currGlobalNodeIds->getValue<node_id>(j);
+ globalNodeIdMap[currGlobalNodeId][i] = j;
+ }
+ }
+
+ std::vector<shared_ptr<XdmfMap> > returnValue;
+ returnValue.resize(globalNodeIds.size());
+
+ // fill maps for each partition
+ for(unsigned int i=0; i<globalNodeIds.size(); ++i) {
+ shared_ptr<XdmfMap> map = XdmfMap::New();
+ returnValue[i] = map;
+ const shared_ptr<XdmfAttribute> currGlobalNodeIds = globalNodeIds[i];
+
+ for(unsigned int j=0; j<currGlobalNodeIds->getSize(); ++j) {
+ const node_id currGlobalNodeId = currGlobalNodeIds->getValue<node_id>(j);
+ const std::map<task_id, node_id> & currMap =
+ globalNodeIdMap[currGlobalNodeId];
+ if(currMap.size() > 1) {
+ for(std::map<task_id, node_id>::const_iterator iter = currMap.begin();
+ iter != currMap.end();
+ ++iter) {
+ if(iter->first != (int)i) {
+ map->insert(iter->first, j, iter->second);
+ }
+ }
+ }
+ }
+ if(releaseGlobalNodeIds[i]) {
+ currGlobalNodeIds->release();
+ }
+ }
+
+ return returnValue;
+}
+
+XdmfMap::XdmfMap() :
+ mName("")
+{
+}
+
+XdmfMap::XdmfMap(XdmfMap & refMap):
+ mLocalNodeIdsControllers(refMap.mLocalNodeIdsControllers),
+ mMap(refMap.mMap),
+ mName(refMap.mName),
+ mRemoteLocalNodeIdsControllers(refMap.mRemoteLocalNodeIdsControllers),
+ mRemoteTaskIdsControllers(refMap.mRemoteTaskIdsControllers)
+{
+}
+
+XdmfMap::~XdmfMap()
+{
+}
+
+const std::string XdmfMap::ItemTag = "Map";
+
+std::map<std::string, std::string>
+XdmfMap::getItemProperties() const
+{
+ std::map<std::string, std::string> mapProperties;
+ mapProperties.insert(std::make_pair("Name", mName));
+ return mapProperties;
+}
+
+std::string
+XdmfMap::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::map<XdmfMap::task_id, XdmfMap::node_id_map>
+XdmfMap::getMap() const
+{
+ return mMap;
+}
+
+std::string
+XdmfMap::getName() const
+{
+ return mName;
+}
+
+XdmfMap::node_id_map
+XdmfMap::getRemoteNodeIds(const task_id remoteTaskId)
+{
+ std::map<task_id, node_id_map>::const_iterator iter =
+ mMap.find(remoteTaskId);
+ if(iter != mMap.end()) {
+ return iter->second;
+ }
+ // No entry, return empty map.
+ return node_id_map();
+}
+
+void
+XdmfMap::insert(const task_id remoteTaskId,
+ const node_id localNodeId,
+ const node_id remoteLocalNodeId)
+{
+ mMap[remoteTaskId][localNodeId].insert(remoteLocalNodeId);
+ this->setIsChanged(true);
+}
+
+bool XdmfMap::isInitialized() const
+{
+ return mMap.size() > 0;
+}
+
+void
+XdmfMap::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ std::map<std::string, std::string>::const_iterator name =
+ itemProperties.find("Name");
+ if(name != itemProperties.end()) {
+ mName = name->second;
+ }
+ else {
+ mName = "";
+ }
+ std::vector<shared_ptr<XdmfArray> > arrayVector;
+ arrayVector.reserve(3);
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ arrayVector.push_back(array);
+ }
+ }
+
+ if(arrayVector.size() != 0) {
+ if(arrayVector.size() != 3) {
+ XdmfError::message(XdmfError::FATAL,
+ "Expected 3 arrays attached to "
+ "XdmfMap::populateItem");
+ }
+ if(!(arrayVector[0]->getSize() == arrayVector[1]->getSize() &&
+ arrayVector[0]->getSize() == arrayVector[2]->getSize())) {
+ XdmfError::message(XdmfError::FATAL,
+ "Arrays must be of equal size in "
+ "XdmfMap:: populateItem");
+ }
+
+ // check if any arrays have values in memory - if so, they need to be
+ // read into map
+ bool needToRead = false;
+ for(std::vector<shared_ptr<XdmfArray> >::const_iterator iter =
+ arrayVector.begin();
+ iter != arrayVector.end();
+ ++iter) {
+ if((*iter)->isInitialized()) {
+ needToRead = true;
+ break;
+ }
+ }
+
+ if(needToRead) {
+ for(std::vector<shared_ptr<XdmfArray> >::const_iterator iter =
+ arrayVector.begin();
+ iter != arrayVector.end();
+ ++iter) {
+ if(!(*iter)->isInitialized()) {
+ (*iter)->read();
+ }
+ }
+ for(unsigned int i=0; i<arrayVector[0]->getSize(); ++i) {
+ this->insert(arrayVector[0]->getValue<task_id>(i),
+ arrayVector[1]->getValue<node_id>(i),
+ arrayVector[2]->getValue<node_id>(i));
+ }
+ }
+ else {
+
+ mRemoteTaskIdsControllers.clear();
+ for (unsigned int i = 0; i < arrayVector[0]->getNumberHeavyDataControllers(); ++i)
+ {
+ mRemoteTaskIdsControllers.push_back(arrayVector[0]->getHeavyDataController(i));
+ }
+ mLocalNodeIdsControllers.clear();
+ for (unsigned int i = 0; i < arrayVector[1]->getNumberHeavyDataControllers(); ++i)
+ {
+ mLocalNodeIdsControllers.push_back(arrayVector[1]->getHeavyDataController(i));
+ }
+ mRemoteLocalNodeIdsControllers.clear();
+ for (unsigned int i = 0; i < arrayVector[2]->getNumberHeavyDataControllers(); ++i)
+ {
+ mRemoteLocalNodeIdsControllers.push_back(arrayVector[2]->getHeavyDataController(i));
+ }
+ }
+ }
+}
+
+void
+XdmfMap::read()
+{
+ if(mLocalNodeIdsControllers.size() > 0 &&
+ mRemoteTaskIdsControllers.size() > 0 &&
+ mRemoteLocalNodeIdsControllers.size() > 0) {
+
+ unsigned int localNodeCount = 0;
+ for (unsigned int i = 0; i< mLocalNodeIdsControllers.size(); ++i)
+ {
+ localNodeCount += mLocalNodeIdsControllers[i]->getSize();
+ }
+ unsigned int remoteTaskCount = 0;
+ for (unsigned int i = 0; i< mRemoteTaskIdsControllers.size(); ++i)
+ {
+ remoteTaskCount += mRemoteTaskIdsControllers[i]->getSize();
+ }
+ unsigned int remoteNodeCount = 0;
+ for (unsigned int i = 0; i< mRemoteLocalNodeIdsControllers.size(); ++i)
+ {
+ remoteNodeCount += mRemoteLocalNodeIdsControllers[i]->getSize();
+ }
+
+ if(!(localNodeCount ==
+ remoteTaskCount &&
+ localNodeCount ==
+ remoteNodeCount)){
+ XdmfError::message(XdmfError::FATAL,
+ "Arrays must be of equal size in XdmfMap::read");
+ }
+
+ shared_ptr<XdmfArray> remoteTaskIds = XdmfArray::New();
+ shared_ptr<XdmfArray> localNodeIds = XdmfArray::New();
+ shared_ptr<XdmfArray> remoteLocalNodeIds = XdmfArray::New();
+
+ mRemoteTaskIdsControllers[0]->read(remoteTaskIds.get());
+ for (unsigned int i = 1; i < mRemoteTaskIdsControllers.size(); ++i)
+ {
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ mRemoteTaskIdsControllers[i]->read(tempArray.get());
+ remoteTaskIds->insert(remoteTaskIds->getSize(), tempArray, 0, tempArray->getSize());
+ }
+ mLocalNodeIdsControllers[0]->read(localNodeIds.get());
+ for (unsigned int i = 1; i < mLocalNodeIdsControllers.size(); ++i)
+ {
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ mLocalNodeIdsControllers[i]->read(tempArray.get());
+ localNodeIds->insert(localNodeIds->getSize(), tempArray, 0, tempArray->getSize());
+ }
+ mRemoteLocalNodeIdsControllers[0]->read(remoteLocalNodeIds.get());
+ for (unsigned int i = 1; i < mRemoteLocalNodeIdsControllers.size(); ++i)
+ {
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ mRemoteLocalNodeIdsControllers[i]->read(tempArray.get());
+ remoteLocalNodeIds->insert(remoteLocalNodeIds->getSize(), tempArray, 0, tempArray->getSize());
+ }
+
+ for(unsigned int i=0; i<remoteTaskIds->getSize(); ++i) {
+ const unsigned int remoteTaskId = remoteTaskIds->getValue<task_id>(i);
+ const unsigned int localNodeId = localNodeIds->getValue<node_id>(i);
+ const unsigned int remoteLocalNodeId =
+ remoteLocalNodeIds->getValue<node_id>(i);
+ mMap[remoteTaskId][localNodeId].insert(remoteLocalNodeId);
+ }
+ }
+}
+
+
+void
+XdmfMap::release()
+{
+ mMap.clear();
+}
+
+void
+XdmfMap::setHeavyDataControllers(std::vector<shared_ptr<XdmfHeavyDataController> > remoteTaskIdsControllers,
+ std::vector<shared_ptr<XdmfHeavyDataController> > localNodeIdsControllers,
+ std::vector<shared_ptr<XdmfHeavyDataController> > remoteLocalNodeIdsControllers)
+{
+ unsigned int localNodeCount = 0;
+ for (unsigned int i = 0; i< localNodeIdsControllers.size(); ++i)
+ {
+ localNodeCount += localNodeIdsControllers[i]->getSize();
+ }
+ unsigned int remoteTaskCount = 0;
+ for (unsigned int i = 0; i< remoteTaskIdsControllers.size(); ++i)
+ {
+ remoteTaskCount += remoteTaskIdsControllers[i]->getSize();
+ }
+ unsigned int remoteNodeCount = 0;
+ for (unsigned int i = 0; i< remoteLocalNodeIdsControllers.size(); ++i)
+ {
+ remoteNodeCount += remoteLocalNodeIdsControllers[i]->getSize();
+ }
+ if(!(localNodeCount ==
+ remoteTaskCount &&
+ localNodeCount ==
+ remoteNodeCount)) {
+ XdmfError::message(XdmfError::FATAL,
+ "Arrays must be of equal size in "
+ "XdmfMap::setHeavyDataControllers");
+ }
+ mRemoteTaskIdsControllers = remoteTaskIdsControllers;
+ mLocalNodeIdsControllers = localNodeIdsControllers;
+ mRemoteLocalNodeIdsControllers = remoteLocalNodeIdsControllers;
+ this->setIsChanged(true);
+}
+
+void
+XdmfMap::setMap(std::map<task_id, node_id_map> map)
+{
+ mMap = map;
+ this->setIsChanged(true);
+}
+
+void
+XdmfMap::setName(const std::string & name)
+{
+ mName = name;
+ this->setIsChanged(true);
+}
+
+void
+XdmfMap::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+
+ shared_ptr<XdmfArray> remoteTaskIds = XdmfArray::New();
+ shared_ptr<XdmfArray> localNodeIds = XdmfArray::New();
+ shared_ptr<XdmfArray> remoteLocalNodeIds = XdmfArray::New();
+
+ for(std::map<task_id, node_id_map>::const_iterator
+ iter = mMap.begin();
+ iter != mMap.end();
+ ++iter) {
+ for(node_id_map::const_iterator
+ iter2 = iter->second.begin();
+ iter2 != iter->second.end();
+ ++iter2) {
+ for(node_id_map::mapped_type::const_iterator iter3 =
+ iter2->second.begin();
+ iter3 != iter2->second.end();
+ ++iter3) {
+ remoteTaskIds->pushBack(iter->first);
+ localNodeIds->pushBack(iter2->first);
+ remoteLocalNodeIds->pushBack(*iter3);
+ }
+ }
+ }
+
+ for (unsigned int i = 0; i < mRemoteTaskIdsControllers.size(); ++i)
+ {
+ remoteTaskIds->insert(mRemoteTaskIdsControllers[i]);
+ }
+ for (unsigned int i = 0; i < mLocalNodeIdsControllers.size(); ++i)
+ {
+ localNodeIds->insert(mLocalNodeIdsControllers[i]);
+ }
+ for (unsigned int i = 0; i < mRemoteLocalNodeIdsControllers.size(); ++i)
+ {
+ remoteLocalNodeIds->insert(mRemoteLocalNodeIdsControllers[i]);
+ }
+
+ bool originalXPath;
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ originalXPath = writer->getWriteXPaths();
+ writer->setWriteXPaths(false);
+ }
+
+ remoteTaskIds->accept(visitor);
+ localNodeIds->accept(visitor);
+ remoteLocalNodeIds->accept(visitor);
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ writer->setWriteXPaths(originalXPath);
+ }
+
+ mLocalNodeIdsControllers.clear();
+ mRemoteTaskIdsControllers.clear();
+ mRemoteLocalNodeIdsControllers.clear();
+
+ for (unsigned int i = 0; i < remoteTaskIds->getNumberHeavyDataControllers(); ++i)
+ {
+ mRemoteTaskIdsControllers.push_back(remoteTaskIds->getHeavyDataController(i));
+ }
+ for (unsigned int i = 0; i < localNodeIds->getNumberHeavyDataControllers(); ++i)
+ {
+ mLocalNodeIdsControllers.push_back(localNodeIds->getHeavyDataController(i));
+ }
+ for (unsigned int i = 0; i < remoteLocalNodeIds->getNumberHeavyDataControllers(); ++i)
+ {
+ mRemoteLocalNodeIdsControllers.push_back(remoteLocalNodeIds->getHeavyDataController(i));
+ }
+
+ remoteTaskIds.reset();
+ localNodeIds.reset();
+ remoteLocalNodeIds.reset();
+}
+
+// C Wrappers
+
+XDMFMAP * XdmfMapNew()
+{
+ try
+ {
+ shared_ptr<XdmfMap> generatedMap = XdmfMap::New();
+ return (XDMFMAP *)((void *)(new XdmfMap(*generatedMap.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfMap> generatedMap = XdmfMap::New();
+ return (XDMFMAP *)((void *)(new XdmfMap(*generatedMap.get())));
+ }
+}
+
+XDMFMAP ** XdmfMapNewFromIdVector(int ** globalNodeIds, int * numIdsOnNode, int numIds)
+{
+ try
+ {
+ std::vector<shared_ptr<XdmfAttribute> > insertedAttributeVector;
+ for (int i = 0; i < numIds; ++i) {
+ shared_ptr<XdmfAttribute> insertedAttribute = XdmfAttribute::New();
+ insertedAttribute->insert(0, globalNodeIds[i], numIdsOnNode[i], 1, 1);
+ insertedAttributeVector.push_back(insertedAttribute);
+ }
+ std::vector<shared_ptr<XdmfMap> > generatedMaps = XdmfMap::New(insertedAttributeVector);
+ unsigned int returnSize = generatedMaps.size();
+ XDMFMAP ** returnArray = new XDMFMAP *[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = (XDMFMAP *)((void *)(new XdmfMap(*generatedMaps[i].get())));
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<shared_ptr<XdmfAttribute> > insertedAttributeVector;
+ for (int i = 0; i < numIds; ++i) {
+ shared_ptr<XdmfAttribute> insertedAttribute = XdmfAttribute::New();
+ insertedAttribute->insert(0, globalNodeIds[i], numIdsOnNode[i], 1, 1);
+ insertedAttributeVector.push_back(insertedAttribute);
+ }
+ std::vector<shared_ptr<XdmfMap> > generatedMaps = XdmfMap::New(insertedAttributeVector);
+ unsigned int returnSize = generatedMaps.size();
+ XDMFMAP ** returnArray = new XDMFMAP *[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = (XDMFMAP *)((void *)(new XdmfMap(*generatedMaps[i].get())));
+ }
+ return returnArray;
+ }
+}
+
+char * XdmfMapGetName(XDMFMAP * map)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfMap *)(map))->getName().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfMap *)(map))->getName().c_str());
+ return returnPointer;
+ }
+}
+
+void XdmfMapInsert(XDMFMAP * map, int remoteTaskId, int localNodeId, int remoteLocalNodeId)
+{
+ ((XdmfMap *)(map))->insert(remoteTaskId, localNodeId, remoteLocalNodeId);
+}
+
+int XdmfMapIsInitialized(XDMFMAP * map)
+{
+ return ((XdmfMap *)(map))->isInitialized();
+}
+
+void XdmfMapRead(XDMFMAP * map, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfMap *)(map))->read();
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfMapRelease(XDMFMAP * map)
+{
+ ((XdmfMap *)(map))->release();
+}
+
+int * XdmfMapRetrieveLocalNodeIds(XDMFMAP * map, int remoteTaskId)
+{
+ try
+ {
+ int * returnPointer = new int[XdmfMapRetrieveNumberLocalNodeIds(map, remoteTaskId)]();
+ std::map<int, std::map<int, std::set<int> > > testMap = ((XdmfMap *)(map))->getMap();
+ std::map<int, std::map<int, std::set<int> > >::const_iterator iter = testMap.find(remoteTaskId);
+ unsigned int i = 0;
+ for(std::map<int, std::set<int> >::const_iterator
+ iter2 = iter->second.begin();
+ iter2 != iter->second.end();
+ ++iter2) {
+ returnPointer[i] = iter2->first;
+ ++i;
+ }
+ return returnPointer;
+ }
+ catch (...)
+ {
+ int * returnPointer = new int[XdmfMapRetrieveNumberLocalNodeIds(map, remoteTaskId)]();
+ std::map<int, std::map<int, std::set<int> > > testMap = ((XdmfMap *)(map))->getMap();
+ std::map<int, std::map<int, std::set<int> > >::const_iterator iter = testMap.find(remoteTaskId);
+ unsigned int i = 0;
+ for(std::map<int, std::set<int> >::const_iterator
+ iter2 = iter->second.begin();
+ iter2 != iter->second.end();
+ ++iter2) {
+ returnPointer[i] = iter2->first;
+ ++i;
+ }
+ return returnPointer;
+ }
+}
+
+int XdmfMapRetrieveNumberLocalNodeIds(XDMFMAP * map, int remoteTaskId)
+{
+ return ((XdmfMap *)(map))->getMap()[remoteTaskId].size();
+}
+
+int XdmfMapRetrieveNumberRemoteTaskIds(XDMFMAP * map)
+{
+ return ((XdmfMap *)(map))->getMap().size();
+}
+
+int XdmfMapRetrieveNumberRemoteNodeIds(XDMFMAP * map, int remoteTaskId, int localNodeId)
+{
+ return ((XdmfMap *)(map))->getMap()[remoteTaskId][localNodeId].size();
+}
+
+int * XdmfMapRetrieveRemoteTaskIds(XDMFMAP * map)
+{
+ try
+ {
+ int * returnPointer = new int[((XdmfMap *)(map))->getMap().size()]();
+ std::map<int, std::map<int, std::set<int> > > testMap = ((XdmfMap *)(map))->getMap();
+ unsigned int i = 0;
+ for(std::map<int, std::map<int, std::set<int> > >::const_iterator
+ iter = testMap.begin();
+ iter != testMap.end();
+ ++iter) {
+ returnPointer[i] = iter->first;
+ ++i;
+ }
+ return returnPointer;
+ }
+ catch (...)
+ {
+ int * returnPointer = new int[((XdmfMap *)(map))->getMap().size()]();
+ std::map<int, std::map<int, std::set<int> > > testMap = ((XdmfMap *)(map))->getMap();
+ unsigned int i = 0;
+ for(std::map<int, std::map<int, std::set<int> > >::const_iterator
+ iter = testMap.begin();
+ iter != testMap.end();
+ ++iter) {
+ returnPointer[i] = iter->first;
+ ++i;
+ }
+ return returnPointer;
+ }
+}
+
+int * XdmfMapRetrieveRemoteNodeIds(XDMFMAP * map, int remoteTaskId, int localNodeId)
+{
+ try
+ {
+ int * returnPointer = new int[XdmfMapRetrieveNumberRemoteNodeIds(map, remoteTaskId, localNodeId)]();
+ std::map<int, std::map<int, std::set<int> > > testMap = ((XdmfMap *)(map))->getMap();
+ std::map<int, std::map<int, std::set<int> > >::const_iterator iter = testMap.find(remoteTaskId);
+ std::map<int, std::set<int> >::const_iterator iter2 = iter->second.find(localNodeId);
+ unsigned int i = 0;
+ for(std::map<int, std::set<int> >::mapped_type::const_iterator iter3 =
+ iter2->second.begin();
+ iter3 != iter2->second.end();
+ ++iter3) {
+ returnPointer[i] = *iter3;
+ i++;
+ }
+ return returnPointer;
+ }
+ catch (...)
+ {
+ int * returnPointer = new int[XdmfMapRetrieveNumberRemoteNodeIds(map, remoteTaskId, localNodeId)]();
+ std::map<int, std::map<int, std::set<int> > > testMap = ((XdmfMap *)(map))->getMap();
+ std::map<int, std::map<int, std::set<int> > >::const_iterator iter = testMap.find(remoteTaskId);
+ std::map<int, std::set<int> >::const_iterator iter2 = iter->second.find(localNodeId);
+ unsigned int i = 0;
+ for(std::map<int, std::set<int> >::mapped_type::const_iterator iter3 =
+ iter2->second.begin();
+ iter3 != iter2->second.end();
+ ++iter3) {
+ returnPointer[i] = *iter3;
+ i++;
+ }
+ return returnPointer;
+ }
+}
+
+void XdmfMapSetHeavyDataControllers(XDMFMAP * map,
+ XDMFHEAVYDATACONTROLLER ** remoteTaskControllers,
+ int numRemoteTaskControllers,
+ XDMFHEAVYDATACONTROLLER ** localNodeControllers,
+ int numLocalNodeControllers,
+ XDMFHEAVYDATACONTROLLER ** remoteLocalNodeControllers,
+ int numRemoteLocalNodeControllers,
+ int passControl,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<shared_ptr<XdmfHeavyDataController> > insertRemoteTaskControllers;
+ for (int i = 0; i < numRemoteTaskControllers; ++i) {
+ if (passControl) {
+ insertRemoteTaskControllers.push_back(shared_ptr<XdmfHeavyDataController>(((XdmfHeavyDataController *)remoteTaskControllers[i])));
+ }
+ else {
+ insertRemoteTaskControllers.push_back(shared_ptr<XdmfHeavyDataController>(((XdmfHeavyDataController *)remoteTaskControllers[i]), XdmfNullDeleter()));
+ }
+ }
+
+ std::vector<shared_ptr<XdmfHeavyDataController> > insertLocalNodeControllers;
+ for (int i = 0; i < numLocalNodeControllers; ++i) {
+ if (passControl) {
+ insertLocalNodeControllers.push_back(shared_ptr<XdmfHeavyDataController>(((XdmfHeavyDataController *)localNodeControllers[i])));
+ }
+ else {
+ insertLocalNodeControllers.push_back(shared_ptr<XdmfHeavyDataController>(((XdmfHeavyDataController *)localNodeControllers[i]), XdmfNullDeleter()));
+ }
+ }
+
+ std::vector<shared_ptr<XdmfHeavyDataController> > insertRemoteLocalNodeControllers;
+ for (int i = 0; i < numRemoteLocalNodeControllers; ++i) {
+ if (passControl) {
+ insertRemoteLocalNodeControllers.push_back(shared_ptr<XdmfHeavyDataController>(((XdmfHeavyDataController *)remoteLocalNodeControllers[i])));
+ }
+ else {
+ insertRemoteLocalNodeControllers.push_back(shared_ptr<XdmfHeavyDataController>(((XdmfHeavyDataController *)remoteLocalNodeControllers[i]), XdmfNullDeleter()));
+ }
+ }
+ ((XdmfMap *)(map))->setHeavyDataControllers(insertRemoteTaskControllers, insertLocalNodeControllers, insertRemoteLocalNodeControllers);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfMapSetName(XDMFMAP * map, char * newName)
+{
+ ((XdmfMap *)(map))->setName(std::string(newName));
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfMap, XDMFMAP)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfMap.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFMAP_HPP_
+#define XDMFMAP_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItem.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+class XdmfAttribute;
+class XdmfHeavyDataController;
+
+// Includes
+
+#include <set>
+
+/**
+ * @brief Boundary communicator map for partitioned spatial
+ * collections.
+ *
+ * Provides mechanism for mapping nodes across partition
+ * boundaries. Each partitioned grid contains its own map, mapping its
+ * own nodes to all other nodes in the global system.
+ *
+ * There are two methods for constructing XdmfMaps:
+ *
+ * Calling New() with no parameters will construct an empty map. The
+ * map can be filled manually with subsequent insert commands.
+ *
+ * Calling New(const std::vector<shared_ptr<XdmfAttribute> > &
+ * globalNodeIds) will construct XdmfMaps for each grid in an entire
+ * global system. Each entry in the vector contains the globalNodeIds
+ * for that partition. The constructor accepts global node ids for
+ * each partition to construct the proper XdmfMaps.
+ */
+class XDMF_EXPORT XdmfMap : public XdmfItem {
+
+public:
+
+ typedef int node_id;
+ typedef int task_id;
+ typedef std::map<node_id, std::set<node_id> > node_id_map;
+
+ /**
+ * Create a new XdmfMap.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfMap.
+ */
+ static shared_ptr<XdmfMap> New();
+
+ /**
+ * Create XdmfMaps for each grid in a domain decomposed mesh. Each
+ * entry in the globalNodeIds vector contains the global node ids
+ * for that partition.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initializationnode
+ * @until //#initializationnode
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initializationnode
+ * @until #//initializationnode
+ *
+ * @param globalNodeIds A vector of attributes containing globalNodeId
+ * values for each partition to be mapped.
+ *
+ * @return Constructed XdmfMaps for each partition. The
+ * size of the vector will be the same as the
+ * globalNodeIds vector.
+ */
+ static std::vector<shared_ptr<XdmfMap> >
+ New(const std::vector<shared_ptr<XdmfAttribute> > & globalNodeIds);
+
+ virtual ~XdmfMap();
+
+ LOKI_DEFINE_VISITABLE(XdmfMap, XdmfItem)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ /**
+ * Get stored boundary communicator map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getMap
+ * @until //#getMap
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getMap
+ * @until #//getMap
+ *
+ * @return Stored boundary communicator map.
+ */
+ std::map<task_id, node_id_map> getMap() const;
+
+ /**
+ * Get name of boundary communicator map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return Name of boundary communicator map.
+ */
+ std::string getName() const;
+
+ /**
+ * Given a remote task id return a map of local node ids to remote
+ * node ids
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getRemoteNodeIds
+ * @until //#getRemoteNodeIds
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getRemoteNodeIds
+ * @until #//getRemoteNodeIds
+ *
+ * @param remoteTaskId Task id to retrieve mapping for.
+ *
+ * @return A map of local node ids to a vector of
+ * remote node ids on remoteTaskId.
+ */
+ node_id_map getRemoteNodeIds(const task_id remoteTaskId);
+
+ std::string getItemTag() const;
+
+ using XdmfItem::insert;
+
+ /**
+ * Insert a new entry in map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#inserttuple
+ * @until //#inserttuple
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//inserttuple
+ * @until #//inserttuple
+ *
+ * @param remoteTaskId task id where the remoteLoalNodeId is
+ * located.
+ * @param localNodeId The node id of the node being mapped.
+ * @param remoteLocalNodeId A node id on the remoteTaskId that the
+ * localNodeId is mapped to.
+ */
+ void insert(const task_id remoteTaskId,
+ const node_id localNodeId,
+ const node_id remoteLocalNodeId);
+
+ /**
+ * Returns whether the map is initialized (contains values in
+ * memory).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#isInitialized
+ * @until //#isInitialized
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline #//isInitialized
+ * @until #//isInitialized
+ *
+ * @return bool true if map contains values in memory.
+ */
+ bool isInitialized() const;
+
+ /**
+ * Read data from disk into memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#isInitialized
+ * @until //#isInitialized
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline #//isInitialized
+ * @until #//isInitialized
+ */
+ void read();
+
+ /**
+ * Release all data held in memory. The heavy data remain attached.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#release
+ * @until //#release
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline #//release
+ * @until #//release
+ */
+ void release();
+
+ /**
+ * Set the heavy data controllers for this map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setHeavyDataController
+ * @until //#setHeavyDataController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline #//setHeavyDataController
+ * @until #//setHeavyDataController
+ *
+ * @param remoteTaskIdsControllers A vector of XdmfHeavyDataControllers
+ * to the remote task ids dataset.
+ * @param localNodeIdsControllers A vector of XdmfHeavyDataControllers
+ * to the local node ids dataset.
+ * @param remoteLocalNodeIdsControllers A vector of XdmfHeavyDataControllers
+ * to the remote local node ids dataset.
+ */
+ void
+ setHeavyDataControllers(std::vector<shared_ptr<XdmfHeavyDataController> > remoteTaskIdsControllers,
+ std::vector<shared_ptr<XdmfHeavyDataController> > localNodeIdsControllers,
+ std::vector<shared_ptr<XdmfHeavyDataController> > remoteLocalNodeIdsControllers);
+
+ /**
+ * Set the boundary communicator map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setMap
+ * @until //#setMap
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setMap
+ * @until #//setMap
+ *
+ * @param map The boundary communicator map to store.
+ */
+ void setMap(std::map<task_id, node_id_map> map);
+
+ /**
+ * Set the name of the boundary communicator map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfMap.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleMap.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ *
+ * @param name The name of the boundary communicator map to set.
+ */
+ void setName(const std::string & name);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfMap(XdmfMap & map);
+
+protected:
+
+ XdmfMap();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfMap(const XdmfMap & map); // Not implemented.
+ void operator=(const XdmfMap & map); // Not implemented.
+
+ std::vector<shared_ptr<XdmfHeavyDataController> > mLocalNodeIdsControllers;
+ // remoteTaskId | localNodeId | remoteLocalNodeId
+ std::map<task_id, node_id_map > mMap;
+ std::string mName;
+ std::vector<shared_ptr<XdmfHeavyDataController> > mRemoteLocalNodeIdsControllers;
+ std::vector<shared_ptr<XdmfHeavyDataController> > mRemoteTaskIdsControllers;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFMAP; // Simply as a typedef to ensure correct typing
+typedef struct XDMFMAP XDMFMAP;
+
+XDMF_EXPORT XDMFMAP * XdmfMapNew();
+
+XDMF_EXPORT XDMFMAP ** XdmfMapNewFromIdVector(int ** globalNodeIds, int * numIdsOnNode, int numIds);
+
+XDMF_EXPORT char * XdmfMapGetName(XDMFMAP * map);
+
+XDMF_EXPORT void XdmfMapInsert(XDMFMAP * map, int remoteTaskId, int localNodeId, int remoteLocalNodeId);
+
+XDMF_EXPORT int XdmfMapIsInitialized(XDMFMAP * map);
+
+XDMF_EXPORT void XdmfMapRead(XDMFMAP * map, int * status);
+
+XDMF_EXPORT void XdmfMapRelease(XDMFMAP * map);
+
+XDMF_EXPORT int * XdmfMapRetrieveLocalNodeIds(XDMFMAP * map, int remoteTaskId);
+
+XDMF_EXPORT int XdmfMapRetrieveNumberLocalNodeIds(XDMFMAP * map, int remoteTaskId);
+
+XDMF_EXPORT int XdmfMapRetrieveNumberRemoteTaskIds(XDMFMAP * map);
+
+XDMF_EXPORT int XdmfMapRetrieveNumberRemoteNodeIds(XDMFMAP * map, int remoteTaskId, int localNodeId);
+
+XDMF_EXPORT int * XdmfMapRetrieveRemoteTaskIds(XDMFMAP * map);
+
+XDMF_EXPORT int * XdmfMapRetrieveRemoteNodeIds(XDMFMAP * map, int remoteTaskId, int localNodeId);
+
+XDMF_EXPORT void XdmfMapSetHeavyDataControllers(XDMFMAP * map,
+ XDMFHEAVYDATACONTROLLER ** remoteTaskControllers,
+ int numRemoteTaskControllers,
+ XDMFHEAVYDATACONTROLLER ** localNodeControllers,
+ int numberLocalNodeControllers,
+ XDMFHEAVYDATACONTROLLER ** remoteLocalNodeControllers,
+ int numRemoteLocalNodeControllers,
+ int passControl,
+ int * status);
+
+XDMF_EXPORT void XdmfMapSetName(XDMFMAP * map, char * newName);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfMap, XDMFMAP, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFMAP_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfReader.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfItemFactory.hpp"
+#include "XdmfReader.hpp"
+#include "XdmfError.hpp"
+
+shared_ptr<XdmfReader>
+XdmfReader::New()
+{
+ shared_ptr<XdmfReader> p(new XdmfReader());
+ return p;
+}
+
+XdmfReader::XdmfReader() :
+ XdmfCoreReader(XdmfItemFactory::New())
+{
+}
+
+XdmfReader::XdmfReader(const XdmfReader &) :
+ XdmfCoreReader(XdmfItemFactory::New())
+{
+}
+
+XdmfReader::~XdmfReader()
+{
+}
+
+XdmfItem *
+XdmfReader::DuplicatePointer(shared_ptr<XdmfItem> original) const
+{
+ return XdmfCoreReader::DuplicatePointer(original);
+}
+
+// Implemented to make SWIG wrapping work correctly
+// (typemaps to return specific subclass instances of XdmfItems)
+shared_ptr<XdmfItem>
+XdmfReader::read(const std::string & filePath) const
+{
+ return XdmfCoreReader::read(filePath);
+}
+
+std::vector<shared_ptr<XdmfItem> >
+XdmfReader::read(const std::string & filePath,
+ const std::string & xPath) const
+{
+ return XdmfCoreReader::read(filePath, xPath);
+}
+
+// C Wrappers
+
+XDMFREADER * XdmfReaderNew()
+{
+ shared_ptr<XdmfReader> returnReader = XdmfReader::New();
+ return (XDMFREADER *)((void *)(new XdmfReader(*returnReader.get())));
+}
+
+void XdmfReaderFree(XDMFREADER * item)
+{
+ delete ((XdmfReader *)item);
+}
+
+XDMF_CORE_READER_C_CHILD_WRAPPER(XdmfReader, XDMFREADER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfReader.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFREADER_HPP_
+#define XDMFREADER_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfCoreReader.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Reads an Xdmf file stored on disk into memory.
+ *
+ * Reads an Xdmf file stored on disk into an Xdmf structure in
+ * memory. All light data is parsed in order to create appropriate
+ * Xdmf objects. Heavy data controllers are created and attached to
+ * XdmfArrays but no heavy data is read into memory.
+ */
+class XDMF_EXPORT XdmfReader : public XdmfCoreReader {
+
+public:
+
+ /**
+ * Create a new XdmfReader.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfReader.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleReader.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfReader.
+ */
+ static shared_ptr<XdmfReader> New();
+
+ virtual ~XdmfReader();
+
+ /**
+ * Uses the internal item factory to create a copy of the internal pointer
+ * of the provided shared pointer. Primarily used for C wrapping.
+ *
+ * @param original The source shared pointer that the pointer will be pulled from.
+ * @return A duplicate of the object contained in the pointer.
+ */
+ virtual XdmfItem * DuplicatePointer(shared_ptr<XdmfItem> original) const;
+
+ shared_ptr<XdmfItem> read(const std::string & filePath) const;
+
+ std::vector<shared_ptr<XdmfItem> >
+ read(const std::string & filePath,
+ const std::string & xPath) const;
+
+ XdmfReader(const XdmfReader &);
+
+protected:
+
+ XdmfReader();
+
+private:
+
+ void operator=(const XdmfReader &); // Not implemented.
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFREADER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFREADER XDMFREADER;
+
+XDMF_EXPORT XDMFREADER * XdmfReaderNew();
+
+XDMF_EXPORT void XdmfReaderFree(XDMFREADER * item);
+
+XDMF_CORE_READER_C_CHILD_DECLARE(XdmfReader, XDMFREADER, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFREADER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfRectilinearGrid.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <cmath>
+#include "XdmfArray.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfGeometryType.hpp"
+#include "XdmfRectilinearGrid.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfTopologyType.hpp"
+#include "XdmfError.hpp"
+
+/**
+ * PIMPL
+ */
+class XdmfRectilinearGrid::XdmfRectilinearGridImpl : public XdmfGridImpl {
+
+public:
+
+ class XdmfGeometryRectilinear : public XdmfGeometry
+ {
+
+ public:
+
+ static shared_ptr<XdmfGeometryRectilinear>
+ New(XdmfRectilinearGrid * const rectilinearGrid)
+ {
+ shared_ptr<XdmfGeometryRectilinear>
+ p(new XdmfGeometryRectilinear(rectilinearGrid));
+ return p;
+ }
+
+ unsigned int
+ getNumberPoints() const
+ {
+ const shared_ptr<const XdmfArray> dimensions =
+ mRectilinearGrid->getDimensions();
+ if(dimensions->getSize() == 0) {
+ return 0;
+ }
+ unsigned int toReturn = 1;
+ for(unsigned int i=0; i<dimensions->getSize(); ++i) {
+ toReturn *= dimensions->getValue<unsigned int>(i);
+ }
+ return toReturn;
+ }
+
+ bool isInitialized() const
+ {
+ return true;
+ }
+
+ void
+ traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+ {
+ const std::vector<shared_ptr<XdmfArray> > & coordinates =
+ mRectilinearGrid->getCoordinates();
+ for (unsigned int i = 0; i < coordinates.size(); ++i)
+ {
+ coordinates[i]->accept(visitor);
+ }
+ }
+
+ private:
+
+ XdmfGeometryRectilinear(XdmfRectilinearGrid * const rectilinearGrid) :
+ mRectilinearGrid(rectilinearGrid)
+ {
+ this->setType(XdmfGeometryTypeRectilinear::New(mRectilinearGrid));
+ }
+
+ const XdmfRectilinearGrid * const mRectilinearGrid;
+ };
+
+ class XdmfGeometryTypeRectilinear : public XdmfGeometryType
+ {
+
+ public:
+
+ static shared_ptr<const XdmfGeometryTypeRectilinear>
+ New(const XdmfRectilinearGrid * const rectilinearGrid)
+ {
+ shared_ptr<const XdmfGeometryTypeRectilinear>
+ p(new XdmfGeometryTypeRectilinear(rectilinearGrid));
+ return p;
+ }
+
+ unsigned int
+ getDimensions() const
+ {
+ return mRectilinearGrid->getDimensions()->getSize();
+ }
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const
+ {
+ const unsigned int dimensions = this->getDimensions();
+ if(dimensions == 3) {
+ collectedProperties["Type"] = "VXVYVZ";
+ }
+ else if(dimensions == 2) {
+ collectedProperties["Type"] = "VXVY";
+ }
+ else {
+ collectedProperties["Type"] = "VECTORED";
+ }
+ }
+
+ private:
+
+ XdmfGeometryTypeRectilinear(const XdmfRectilinearGrid * const rectilinearGrid) :
+ XdmfGeometryType("", 0),
+ mRectilinearGrid(rectilinearGrid)
+ {
+ }
+
+ const XdmfRectilinearGrid * const mRectilinearGrid;
+
+ };
+
+ class XdmfTopologyRectilinear : public XdmfTopology
+ {
+
+ public:
+
+ static shared_ptr<XdmfTopologyRectilinear>
+ New(const XdmfRectilinearGrid * const rectilinearGrid)
+ {
+ shared_ptr<XdmfTopologyRectilinear>
+ p(new XdmfTopologyRectilinear(rectilinearGrid));
+ return p;
+ }
+
+ bool isInitialized() const
+ {
+ return true;
+ }
+
+ unsigned int
+ getNumberElements() const
+ {
+ const shared_ptr<const XdmfArray> dimensions =
+ mRectilinearGrid->getDimensions();
+ if(dimensions->getSize() == 0) {
+ return 0;
+ }
+ unsigned int toReturn = 1;
+ for(unsigned int i=0; i<dimensions->getSize(); ++i) {
+ toReturn *= (dimensions->getValue<unsigned int>(i) - 1);
+ }
+ return toReturn;
+ }
+
+ private:
+
+ XdmfTopologyRectilinear(const XdmfRectilinearGrid * const rectilinearGrid) :
+ mRectilinearGrid(rectilinearGrid)
+ {
+ this->setType(XdmfTopologyTypeRectilinear::New(rectilinearGrid));
+ }
+
+ const XdmfRectilinearGrid * const mRectilinearGrid;
+ };
+
+ class XdmfTopologyTypeRectilinear : public XdmfTopologyType
+ {
+
+ public:
+
+ static shared_ptr<const XdmfTopologyTypeRectilinear>
+ New(const XdmfRectilinearGrid * const rectilinearGrid)
+ {
+ shared_ptr<const XdmfTopologyTypeRectilinear>
+ p(new XdmfTopologyTypeRectilinear(rectilinearGrid));
+ return p;
+ }
+
+ unsigned int
+ getEdgesPerElement() const
+ {
+ return calculateHypercubeNumElements(mRectilinearGrid->getDimensions()->getSize(), 1);
+ }
+
+ unsigned int
+ getFacesPerElement() const
+ {
+ return calculateHypercubeNumElements(mRectilinearGrid->getDimensions()->getSize(), 2);
+ }
+
+ unsigned int
+ getNodesPerElement() const
+ {
+ return calculateHypercubeNumElements(mRectilinearGrid->getDimensions()->getSize(), 0);
+ }
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const
+ {
+ shared_ptr<const XdmfArray> dimensions =
+ mRectilinearGrid->getDimensions();
+ if(dimensions->getSize() == 3) {
+ collectedProperties["Type"] = "3DRectMesh";
+ }
+ else if(dimensions->getSize() == 2) {
+ collectedProperties["Type"] = "2DRectMesh";
+ }
+ else {
+ collectedProperties["Type"] = "RectMesh";
+ }
+ collectedProperties["Dimensions"] = dimensions->getValuesString();
+ }
+
+ private:
+
+ XdmfTopologyTypeRectilinear(const XdmfRectilinearGrid * const rectilinearGrid) :
+ XdmfTopologyType(0,
+ 0,
+ std::vector<shared_ptr<const XdmfTopologyType> >(),
+ 0,
+ "foo",
+ XdmfTopologyType::Structured,
+ 0x1101),
+ mRectilinearGrid(rectilinearGrid)
+ {
+ }
+
+ const XdmfRectilinearGrid * const mRectilinearGrid;
+
+ };
+
+ XdmfRectilinearGridImpl(const std::vector<shared_ptr<XdmfArray> > & coordinates) :
+ mCoordinates(coordinates.begin(), coordinates.end())
+ {
+ mGridType = "Rectilinear";
+ }
+
+ XdmfGridImpl * duplicate()
+ {
+ return new XdmfRectilinearGridImpl(mCoordinates);
+ }
+
+ std::vector<shared_ptr<XdmfArray> > mCoordinates;
+};
+
+shared_ptr<XdmfRectilinearGrid>
+XdmfRectilinearGrid::New(const shared_ptr<XdmfArray> xCoordinates,
+ const shared_ptr<XdmfArray> yCoordinates)
+{
+ std::vector<shared_ptr<XdmfArray> > axesCoordinates;
+ axesCoordinates.resize(2);
+ axesCoordinates[0] = xCoordinates;
+ axesCoordinates[1] = yCoordinates;
+ shared_ptr<XdmfRectilinearGrid> p(new XdmfRectilinearGrid(axesCoordinates));
+ return p;
+}
+
+shared_ptr<XdmfRectilinearGrid>
+XdmfRectilinearGrid::New(const shared_ptr<XdmfArray> xCoordinates,
+ const shared_ptr<XdmfArray> yCoordinates,
+ const shared_ptr<XdmfArray> zCoordinates)
+{
+ std::vector<shared_ptr<XdmfArray> > axesCoordinates;
+ axesCoordinates.resize(3);
+ axesCoordinates[0] = xCoordinates;
+ axesCoordinates[1] = yCoordinates;
+ axesCoordinates[2] = zCoordinates;
+ shared_ptr<XdmfRectilinearGrid> p(new XdmfRectilinearGrid(axesCoordinates));
+ return p;
+}
+
+shared_ptr<XdmfRectilinearGrid>
+XdmfRectilinearGrid::New(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates)
+{
+ shared_ptr<XdmfRectilinearGrid> p(new XdmfRectilinearGrid(axesCoordinates));
+ return p;
+}
+
+XdmfRectilinearGrid::XdmfRectilinearGrid(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates) :
+ XdmfGrid(XdmfRectilinearGridImpl::XdmfGeometryRectilinear::New(this),
+ XdmfRectilinearGridImpl::XdmfTopologyRectilinear::New(this))
+{
+ mImpl = new XdmfRectilinearGridImpl(axesCoordinates);
+}
+
+XdmfRectilinearGrid::XdmfRectilinearGrid(XdmfRectilinearGrid & refGrid):
+ XdmfGrid(refGrid)
+{
+ mTopology = XdmfRectilinearGridImpl::XdmfTopologyRectilinear::New(this);
+ mGeometry = XdmfRectilinearGridImpl::XdmfGeometryRectilinear::New(this);
+}
+
+XdmfRectilinearGrid::~XdmfRectilinearGrid()
+{
+ if (mImpl) {
+ delete mImpl;
+ }
+ mImpl = NULL;
+}
+
+const std::string XdmfRectilinearGrid::ItemTag = "Grid";
+
+void
+XdmfRectilinearGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
+{
+ XdmfGrid::copyGrid(sourceGrid);
+ if (shared_ptr<XdmfRectilinearGrid> classedGrid = shared_dynamic_cast<XdmfRectilinearGrid>(sourceGrid))
+ {
+ // Copy stucture from read grid to this grid
+ this->setCoordinates(classedGrid->getCoordinates());
+ }
+}
+
+shared_ptr<XdmfArray>
+XdmfRectilinearGrid::getCoordinates(const unsigned int axisIndex)
+{
+ return boost::const_pointer_cast<XdmfArray>
+ (static_cast<const XdmfRectilinearGrid &>
+ (*this).getCoordinates(axisIndex));
+}
+
+shared_ptr<const XdmfArray>
+XdmfRectilinearGrid::getCoordinates(const unsigned int axisIndex) const
+{
+ if(axisIndex < ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.size()) {
+ return ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates[axisIndex];
+ }
+ return shared_ptr<XdmfArray>();
+}
+
+std::vector<shared_ptr<XdmfArray> >
+XdmfRectilinearGrid::getCoordinates()
+{
+ return static_cast<const XdmfRectilinearGrid &>(*this).getCoordinates();
+}
+
+const std::vector<shared_ptr<XdmfArray> >
+XdmfRectilinearGrid::getCoordinates() const
+{
+ return ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates;
+}
+
+shared_ptr<XdmfArray>
+XdmfRectilinearGrid::getDimensions()
+{
+ return boost::const_pointer_cast<XdmfArray>
+ (static_cast<const XdmfRectilinearGrid &>(*this).getDimensions());
+}
+
+shared_ptr<const XdmfArray>
+XdmfRectilinearGrid::getDimensions() const
+{
+ shared_ptr<XdmfArray> dimensions = XdmfArray::New();
+ std::vector<shared_ptr<XdmfArray> > heldCoordinates =
+ ((XdmfRectilinearGridImpl*)mImpl)->mCoordinates;
+ dimensions->reserve(heldCoordinates.size());
+ for (unsigned int i = 0; i < heldCoordinates.size(); ++i)
+ {
+ dimensions->pushBack(heldCoordinates[i]->getSize());
+ }
+ return dimensions;
+}
+
+void
+XdmfRectilinearGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfGrid::populateItem(itemProperties, childItems, reader);
+
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
+ shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
+ if(rectilinearGrid->getGeometry()->getType()->getDimensions() > 0) {
+ this->setCoordinates(rectilinearGrid->getCoordinates());
+ break;
+ }
+ }
+ }
+}
+
+void
+XdmfRectilinearGrid::read()
+{
+ if (mGridController)
+ {
+ if (shared_ptr<XdmfRectilinearGrid> grid = shared_dynamic_cast<XdmfRectilinearGrid>(mGridController->read()))
+ {
+ // Copy stucture from read grid to this grid
+ copyGrid(grid);
+ }
+ else if (shared_dynamic_cast<XdmfGrid>(mGridController->read()))
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference");
+ }
+ }
+}
+
+void
+XdmfRectilinearGrid::release()
+{
+ XdmfGrid::release();
+ ((XdmfRectilinearGridImpl*)mImpl)->mCoordinates.clear();
+}
+
+void
+XdmfRectilinearGrid::setCoordinates(const unsigned int axisIndex,
+ const shared_ptr<XdmfArray> axisCoordinates)
+{
+ if(((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.size() <= axisIndex) {
+ ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.reserve(axisIndex + 1);
+ unsigned int numArraysToInsert =
+ axisIndex - ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.size() + 1;
+ for(unsigned int i=0; i<numArraysToInsert; ++i) {
+ ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.push_back(XdmfArray::New());
+ }
+ }
+ ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates[axisIndex] = axisCoordinates;
+ this->setIsChanged(true);
+}
+
+void
+XdmfRectilinearGrid::setCoordinates(const std::vector<shared_ptr<XdmfArray> > axesCoordinates)
+{
+ ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates = axesCoordinates;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+XDMFRECTILINEARGRID * XdmfRectilinearGridNew(XDMFARRAY ** axesCoordinates, unsigned int numCoordinates, int passControl)
+{
+ try
+ {
+ std::vector<shared_ptr<XdmfArray> > holderVector;
+ for (unsigned int i = 0; i < numCoordinates; ++i) {
+ if (passControl) {
+ holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i]));
+ }
+ else {
+ holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i], XdmfNullDeleter()));
+ }
+ }
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(holderVector);
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ std::vector<shared_ptr<XdmfArray> > holderVector;
+ for (unsigned int i = 0; i < numCoordinates; ++i) {
+ if (passControl) {
+ holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i]));
+ }
+ else {
+ holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i], XdmfNullDeleter()));
+ }
+ }
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(holderVector);
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+}
+
+XDMFRECTILINEARGRID * XdmfRectilinearGridNew2D(XDMFARRAY * xCoordinates, XDMFARRAY * yCoordinates, int passControl)
+{
+ try
+ {
+ if (passControl) {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ else {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ }
+ catch (...)
+ {
+ if (passControl) {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ else {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ }
+}
+
+XDMFRECTILINEARGRID * XdmfRectilinearGridNew3D(XDMFARRAY * xCoordinates, XDMFARRAY * yCoordinates, XDMFARRAY * zCoordinates, int passControl)
+{
+ try
+ {
+ if (passControl) {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates),
+ shared_ptr<XdmfArray>((XdmfArray *)zCoordinates));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ else {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)zCoordinates, XdmfNullDeleter()));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ }
+ catch (...)
+ {
+ if (passControl) {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates),
+ shared_ptr<XdmfArray>((XdmfArray *)zCoordinates));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ else {
+ shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)zCoordinates, XdmfNullDeleter()));
+ return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
+ }
+ }
+}
+
+XDMFARRAY * XdmfRectilinearGridGetCoordinatesByIndex(XDMFRECTILINEARGRID * grid, unsigned int axisIndex, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
+ return (XDMFARRAY *)((void *)(gridPointer->getCoordinates(axisIndex).get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY ** XdmfRectilinearGridGetCoordinates(XDMFRECTILINEARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ XDMFARRAY ** returnPointer;
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
+ std::vector<shared_ptr<XdmfArray> > heldCoordinates = gridPointer->getCoordinates();
+ returnPointer = new XDMFARRAY *[heldCoordinates.size()]();
+ for (unsigned int i = 0; i < heldCoordinates.size(); ++i) {
+ XDMFARRAY * insertArray = (XDMFARRAY *)((void *)(new XdmfArray(*(heldCoordinates[i].get()))));
+ returnPointer[i] = insertArray;
+ }
+ return returnPointer;
+ }
+ catch (...)
+ {
+ XDMFARRAY ** returnPointer;
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
+ std::vector<shared_ptr<XdmfArray> > heldCoordinates = gridPointer->getCoordinates();
+ returnPointer = new XDMFARRAY *[heldCoordinates.size()]();
+ for (unsigned int i = 0; i < heldCoordinates.size(); ++i) {
+ XDMFARRAY * insertArray = (XDMFARRAY *)((void *)(new XdmfArray(*(heldCoordinates[i].get()))));
+ returnPointer[i] = insertArray;
+ }
+ return returnPointer;
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+int XdmfRectilinearGridGetNumberCoordinates(XDMFRECTILINEARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
+ std::vector<shared_ptr<XdmfArray> > heldCoordinates = gridPointer->getCoordinates();
+ return heldCoordinates.size();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+XDMFARRAY * XdmfRectilinearGridGetDimensions(XDMFRECTILINEARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ XdmfArray * copyArray;
+ shared_ptr<XdmfArray> returnDimensions;
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * classedGrid = dynamic_cast<XdmfGrid *>(classedPointer);
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedGrid);
+ XDMFARRAY * returnArray;
+ returnDimensions = gridPointer->getDimensions();
+ copyArray = new XdmfArray(*(returnDimensions.get()));
+ void * copyVoid = (void *)copyArray;
+ returnArray = (XDMFARRAY *) copyVoid;
+ returnDimensions.reset();
+ return returnArray;
+ }
+ catch (...)
+ {
+ XdmfArray * copyArray;
+ shared_ptr<XdmfArray> returnDimensions;
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfGrid * classedGrid = dynamic_cast<XdmfGrid *>(classedPointer);
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedGrid);
+ XDMFARRAY * returnArray;
+ returnDimensions = gridPointer->getDimensions();
+ copyArray = new XdmfArray(*(returnDimensions.get()));
+ void * copyVoid = (void *)copyArray;
+ returnArray = (XDMFARRAY *) copyVoid;
+ returnDimensions.reset();
+ return returnArray;
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void XdmfRectilinearGridSetCoordinates(XDMFRECTILINEARGRID * grid, XDMFARRAY ** axesCoordinates, unsigned int numCoordinates, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
+ std::vector<shared_ptr<XdmfArray> > holderVector;
+ for (unsigned int i = 0; i < numCoordinates; ++i) {
+ if (passControl) {
+ holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i]));
+ }
+ else {
+ holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i], XdmfNullDeleter()));
+ }
+ }
+ gridPointer->setCoordinates(holderVector);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfRectilinearGridSetCoordinatesByIndex(XDMFRECTILINEARGRID * grid, unsigned int index, XDMFARRAY * coordinates, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setCoordinates(index, shared_ptr<XdmfArray>((XdmfArray *)coordinates));
+ }
+ else {
+ gridPointer->setCoordinates(index, shared_ptr<XdmfArray>((XdmfArray *)coordinates, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfRectilinearGrid, XDMFRECTILINEARGRID)
+XDMF_GRID_C_CHILD_WRAPPER(XdmfRectilinearGrid, XDMFRECTILINEARGRID)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfRectilinearGrid.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFRECTILINEARGRID_HPP_
+#define XDMFRECTILINEARGRID_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfGrid.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+/**
+ * @brief A rectilinear grid consists of cells and points arranged on
+ * a regular lattice in space.
+ *
+ * XdmfRectilinearGrid represents a mesh of cells and points arranged
+ * on a regular lattice in space. Points are arranged along coordinate
+ * axes, but the spacing between points may vary.
+ *
+ * In order to define a rectilinear grid, the coordinates along each
+ * axis direction must be specified.
+ *
+ */
+class XDMF_EXPORT XdmfRectilinearGrid : public XdmfGrid {
+
+public:
+
+ /**
+ * Create a new rectilinear grid (Two dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initialization2
+ * @until //#initialization2
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initialization2
+ * @until #//initialization2
+ *
+ * @param xCoordinates The coordinates of points along the x axis
+ * @param yCoordinates The coordinates of points along the y axis.
+ *
+ * @return Constructed rectilinear grid.
+ */
+ static shared_ptr<XdmfRectilinearGrid>
+ New(const shared_ptr<XdmfArray> xCoordinates,
+ const shared_ptr<XdmfArray> yCoordinates);
+
+ /**
+ * Create a new rectilinear grid (Three dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initialization3
+ * @until //#initialization3
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initialization3
+ * @until #//initialization3
+ *
+ * @param xCoordinates The coordinates of points along the x axis
+ * @param yCoordinates The coordinates of points along the y axis.
+ * @param zCoordinates The coordinates of points along the z axis.
+ *
+ * @return Constructed rectilinear grid.
+ */
+ static shared_ptr<XdmfRectilinearGrid>
+ New(const shared_ptr<XdmfArray> xCoordinates,
+ const shared_ptr<XdmfArray> yCoordinates,
+ const shared_ptr<XdmfArray> zCoordinates);
+
+ /**
+ * Create a new rectilinear grid (N dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ *
+ * @param axesCoordinates The coordinates of points along each axis.
+ *
+ * @return Constructed rectilinear grid.
+ */
+ static shared_ptr<XdmfRectilinearGrid>
+ New(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates);
+
+ virtual ~XdmfRectilinearGrid();
+
+ LOKI_DEFINE_VISITABLE(XdmfRectilinearGrid, XdmfGrid)
+ static const std::string ItemTag;
+
+ /**
+ * Get the coordinates of the grid along a single axis.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getCoodinatessingle
+ * @until //#getCoodinatessingle
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initialization2
+ * @until #//initialization2
+ * @skipline #//getCoodinatessingle
+ * @until #//getCoodinatessingle
+ *
+ * @param axisIndex The index of the axis to retrieve, (i.e. 0 for
+ * x-axis). If no array exists at the index,
+ * return NULL.
+ *
+ * @return Array of coordinates along requested axis
+ */
+ shared_ptr<XdmfArray> getCoordinates(const unsigned int axisIndex);
+
+ /**
+ * Get the coordinates of the grid along a single axis (const
+ * version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getCoodinatessingleconst
+ * @until //#getCoodinatessingleconst
+ *
+ * Python: does not support a constant version of this function
+ *
+ * @param axisIndex The index of the axis to retrieve (i.e. 0 for
+ * x-axis). If no array exists at the index,
+ * return NULL.
+ *
+ * @return Array of coordinates along requeste axis
+ */
+ shared_ptr<const XdmfArray>
+ getCoordinates(const unsigned int axisIndex) const;
+
+ /**
+ * Get the coordinates of the grid along all axes.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#getCoodinatesvector
+ * @until //#getCoodinatesvector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ * @skipline #//getCoodinatesvector
+ * @until #//getCoodinatesvector
+ *
+ * @return Vector containing an array of coordinates along each
+ * direction.
+ */
+ std::vector<shared_ptr<XdmfArray> > getCoordinates();
+
+ /**
+ * Get the coordinates of the grid along all axes (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#getCoodinatesvectorconst
+ * @until //#getCoodinatesvectorconst
+ *
+ * Python: does not support a constant version of this function
+ *
+ * @return Vector containing an array of coordinates along each
+ * direction.
+ */
+ const std::vector<shared_ptr<XdmfArray> > getCoordinates() const;
+
+ /**
+ * Get the dimensions of the grid, the number of points in each
+ * direction.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return XdmfArray containing dimensions of this grid.
+ */
+ shared_ptr<XdmfArray> getDimensions();
+
+ /**
+ * Get the dimensions of the grid, the number of points in each
+ * direction (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#getDimensionsconst
+ * @until //#getDimensionsconst
+ *
+ * Python: Doesn't support a constant version of this function
+ *
+ * @return XdmfArray containing the dimensions of this grid.
+ */
+ shared_ptr<const XdmfArray> getDimensions() const;
+
+ virtual void read();
+
+ virtual void release();
+
+ /**
+ * Set the coordinates of the grid along a single axis.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initialization3
+ * @until //#initialization3
+ * @skipline //#setCoordinatessingle
+ * @until //#setCoordinatessingle
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initialization3
+ * @until #//initialization3
+ * @skipline #//setCoordinatessingle
+ * @until #//setCoordinatessingle
+ *
+ * @param axisIndex The index of the axis to set
+ * (i.e. 0 for x-axis).
+ * @param axisCoordinates The coordinates of points along
+ * a single axis to set.
+ */
+ void setCoordinates(const unsigned int axisIndex,
+ const shared_ptr<XdmfArray> axisCoordinates);
+
+ /**
+ * Set the coordinates of the grid along all axes.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRectilinearGrid.cpp
+ * @skipline //#initvalues
+ * @until //#initvalues
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#setCoordinatesvector
+ * @until //#setCoordinatesvector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRectilinearGrid.py
+ * @skipline #//initvalues
+ * @until #//initvalues
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ * @skipline #//setCoordinatesvector
+ * @until #//setCoordinatesvector
+ *
+ * @param axesCoordinates The coordinates of points
+ * along each axis.
+ */
+ void
+ setCoordinates(const std::vector<shared_ptr<XdmfArray> > axesCoordinates);
+
+ XdmfRectilinearGrid(XdmfRectilinearGrid &);
+
+protected:
+
+ XdmfRectilinearGrid(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates);
+
+ void copyGrid(shared_ptr<XdmfGrid> sourceGrid);
+
+ void populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfRectilinearGridImpl;
+
+ XdmfRectilinearGrid(const XdmfRectilinearGrid &); // Not implemented.
+ void operator=(const XdmfRectilinearGrid &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFRECTILINEARGRID; // Simply as a typedef to ensure correct typing
+typedef struct XDMFRECTILINEARGRID XDMFRECTILINEARGRID;
+
+XDMF_EXPORT XDMFRECTILINEARGRID * XdmfRectilinearGridNew(XDMFARRAY ** axesCoordinates, unsigned int numCoordinates, int passControl);
+
+XDMF_EXPORT XDMFRECTILINEARGRID * XdmfRectilinearGridNew2D(XDMFARRAY * xCoordinates, XDMFARRAY * yCoordinates, int passControl);
+
+XDMF_EXPORT XDMFRECTILINEARGRID * XdmfRectilinearGridNew3D(XDMFARRAY * xCoordinates, XDMFARRAY * yCoordinates, XDMFARRAY * zCoordinates, int passControl);
+
+XDMF_EXPORT XDMFARRAY * XdmfRectilinearGridGetCoordinatesByIndex(XDMFRECTILINEARGRID * grid, unsigned int axisIndex, int * status);
+
+XDMF_EXPORT XDMFARRAY ** XdmfRectilinearGridGetCoordinates(XDMFRECTILINEARGRID * grid, int * status);
+
+XDMF_EXPORT int XdmfRectilinearGridGetNumberCoordinates(XDMFRECTILINEARGRID * grid, int * status);
+
+XDMF_EXPORT XDMFARRAY * XdmfRectilinearGridGetDimensions(XDMFRECTILINEARGRID * grid, int * status);
+
+XDMF_EXPORT void XdmfRectilinearGridSetCoordinates(XDMFRECTILINEARGRID * grid, XDMFARRAY ** axesCoordinates, unsigned int numCoordinates, int passControl, int * status);
+
+XDMF_EXPORT void XdmfRectilinearGridSetCoordinatesByIndex(XDMFRECTILINEARGRID * grid, unsigned int index, XDMFARRAY * coordinates, int passControl, int * status);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfRectilinearGrid, XDMFRECTILINEARGRID, XDMF)
+XDMF_GRID_C_CHILD_DECLARE(XdmfRectilinearGrid, XDMFRECTILINEARGRID, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFRECTILINEARGRID_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfRegularGrid.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <cmath>
+#include "XdmfArray.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfGeometryType.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfTopologyType.hpp"
+#include "XdmfError.hpp"
+
+/**
+ * PIMPL
+ */
+class XdmfRegularGrid::XdmfRegularGridImpl : public XdmfGridImpl {
+
+public:
+
+ class XdmfGeometryRegular : public XdmfGeometry
+ {
+
+ public:
+
+ static shared_ptr<XdmfGeometryRegular>
+ New(XdmfRegularGrid * const regularGrid)
+ {
+ shared_ptr<XdmfGeometryRegular> p(new XdmfGeometryRegular(regularGrid));
+ return p;
+ }
+
+ unsigned int
+ getNumberPoints() const
+ {
+ const shared_ptr<const XdmfArray> dimensions =
+ mRegularGrid->getDimensions();
+ if(dimensions->getSize() == 0) {
+ return 0;
+ }
+ unsigned int toReturn = 1;
+ for(unsigned int i=0; i<dimensions->getSize(); ++i) {
+ toReturn *= dimensions->getValue<unsigned int>(i);
+ }
+ return toReturn;
+ }
+
+ bool isInitialized() const
+ {
+ return true;
+ }
+
+ void
+ traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+ {
+ shared_ptr<XdmfArray> origin = mRegularGrid->getOrigin();
+ shared_ptr<XdmfArray> brickSize = mRegularGrid->getBrickSize();
+ origin->accept(visitor);
+ brickSize->accept(visitor);
+ }
+
+ private:
+
+ XdmfGeometryRegular(XdmfRegularGrid * const regularGrid) :
+ mRegularGrid(regularGrid)
+ {
+ this->setType(XdmfGeometryTypeRegular::New(mRegularGrid));
+ }
+
+ XdmfRegularGrid * const mRegularGrid;
+ };
+
+ class XdmfGeometryTypeRegular : public XdmfGeometryType
+ {
+
+ public:
+
+ static shared_ptr<const XdmfGeometryTypeRegular>
+ New(const XdmfRegularGrid * const regularGrid)
+ {
+ shared_ptr<const XdmfGeometryTypeRegular>
+ p(new XdmfGeometryTypeRegular(regularGrid));
+ return p;
+ }
+
+ unsigned int
+ getDimensions() const
+ {
+ return mRegularGrid->getDimensions()->getSize();
+ }
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const
+ {
+ const unsigned int dimensions = this->getDimensions();
+ if(dimensions == 3) {
+ collectedProperties["Type"] = "ORIGIN_DXDYDZ";
+ }
+ else if(dimensions == 2) {
+ collectedProperties["Type"] = "ORIGIN_DXDY";
+ }
+ else {
+ collectedProperties["Type"] = "ORIGIN_DISPLACEMENT";
+// XdmfError::message(XdmfError::FATAL, "Dimensions not 2 or 3 in XdmfGeometryTypeRegular::getProperties");
+ }
+ }
+
+ private:
+
+ XdmfGeometryTypeRegular(const XdmfRegularGrid * const regularGrid) :
+ XdmfGeometryType("", 0),
+ mRegularGrid(regularGrid)
+ {
+ }
+
+ const XdmfRegularGrid * const mRegularGrid;
+
+ };
+
+ class XdmfTopologyRegular : public XdmfTopology
+ {
+
+ public:
+
+ static shared_ptr<XdmfTopologyRegular>
+ New(const XdmfRegularGrid * const regularGrid)
+ {
+ shared_ptr<XdmfTopologyRegular> p(new XdmfTopologyRegular(regularGrid));
+ return p;
+ }
+
+ bool isInitialized() const
+ {
+ return true;
+ }
+
+ unsigned int
+ getNumberElements() const
+ {
+ const shared_ptr<const XdmfArray> dimensions =
+ mRegularGrid->getDimensions();
+ if(dimensions->getSize() == 0) {
+ return 0;
+ }
+ unsigned int toReturn = 1;
+ for(unsigned int i=0; i<dimensions->getSize(); ++i) {
+ toReturn *= (dimensions->getValue<unsigned int>(i) - 1);
+ }
+ return toReturn;
+ }
+
+ private:
+
+ XdmfTopologyRegular(const XdmfRegularGrid * const regularGrid) :
+ mRegularGrid(regularGrid)
+ {
+ this->setType(XdmfTopologyTypeRegular::New(regularGrid));
+ }
+
+ const XdmfRegularGrid * const mRegularGrid;
+ };
+
+ class XdmfTopologyTypeRegular : public XdmfTopologyType
+ {
+
+ public:
+
+ static shared_ptr<const XdmfTopologyTypeRegular>
+ New(const XdmfRegularGrid * const regularGrid)
+ {
+ shared_ptr<const XdmfTopologyTypeRegular>
+ p(new XdmfTopologyTypeRegular(regularGrid));
+ return p;
+ }
+
+ unsigned int
+ getEdgesPerElement() const
+ {
+ return calculateHypercubeNumElements(mRegularGrid->getDimensions()->getSize(), 1);
+ }
+
+ unsigned int
+ getFacesPerElement() const
+ {
+ return calculateHypercubeNumElements(mRegularGrid->getDimensions()->getSize(), 2);
+ }
+
+ unsigned int
+ getNodesPerElement() const
+ {
+ return calculateHypercubeNumElements(mRegularGrid->getDimensions()->getSize(), 0);
+ }
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const
+ {
+ shared_ptr<const XdmfArray> dimensions = mRegularGrid->getDimensions();
+ if(dimensions->getSize() == 3){
+ collectedProperties["Type"] = "3DCoRectMesh";
+ }
+ else if(dimensions->getSize() == 2) {
+ collectedProperties["Type"] = "2DCoRectMesh";
+ }
+ else {
+ // If not 2 or 3 just mark it as a mesh of unknown dims
+ collectedProperties["Type"] = "CoRectMesh";
+// XdmfError::message(XdmfError::FATAL,
+// "Dimensions not 2 or 3 in "
+// "XdmfTopologyTypeRegular::getProperties");
+ }
+ collectedProperties["Dimensions"] = dimensions->getValuesString();
+ }
+
+ private:
+
+ XdmfTopologyTypeRegular(const XdmfRegularGrid * const regularGrid) :
+ XdmfTopologyType(0, 0, std::vector<shared_ptr<const XdmfTopologyType> >(), 0, "foo", XdmfTopologyType::Structured, 0x1102),
+ mRegularGrid(regularGrid)
+ {
+ }
+
+ const XdmfRegularGrid * const mRegularGrid;
+
+ };
+
+ XdmfRegularGridImpl(const shared_ptr<XdmfArray> brickSize,
+ const shared_ptr<XdmfArray> numPoints,
+ const shared_ptr<XdmfArray> origin) :
+ mBrickSize(brickSize),
+ mDimensions(numPoints),
+ mOrigin(origin)
+ {
+ mGridType = "Regular";
+ }
+
+ XdmfGridImpl * duplicate()
+ {
+ return new XdmfRegularGridImpl(mBrickSize, mDimensions, mOrigin);
+ }
+
+ shared_ptr<XdmfArray> mBrickSize;
+ shared_ptr<XdmfArray> mDimensions;
+ shared_ptr<XdmfArray> mOrigin;
+};
+
+shared_ptr<XdmfRegularGrid>
+XdmfRegularGrid::New(const double xBrickSize,
+ const double yBrickSize,
+ const unsigned int xNumPoints,
+ const unsigned int yNumPoints,
+ const double xOrigin,
+ const double yOrigin)
+{
+ shared_ptr<XdmfArray> brickSize = XdmfArray::New();
+ brickSize->initialize<double>(2);
+ brickSize->insert(0, xBrickSize);
+ brickSize->insert(1, yBrickSize);
+ shared_ptr<XdmfArray> numPoints = XdmfArray::New();
+ numPoints->initialize<unsigned int>(2);
+ numPoints->insert(0, xNumPoints);
+ numPoints->insert(1, yNumPoints);
+ shared_ptr<XdmfArray> origin = XdmfArray::New();
+ origin->initialize<double>(2);
+ origin->insert(0, xOrigin);
+ origin->insert(1, yOrigin);
+ shared_ptr<XdmfRegularGrid> p(new XdmfRegularGrid(brickSize,
+ numPoints,
+ origin));
+ return p;
+}
+
+shared_ptr<XdmfRegularGrid>
+XdmfRegularGrid::New(const double xBrickSize,
+ const double yBrickSize,
+ const double zBrickSize,
+ const unsigned int xNumPoints,
+ const unsigned int yNumPoints,
+ const unsigned int zNumPoints,
+ const double xOrigin,
+ const double yOrigin,
+ const double zOrigin)
+{
+ shared_ptr<XdmfArray> brickSize = XdmfArray::New();
+ brickSize->initialize<double>(3);
+ brickSize->insert(0, xBrickSize);
+ brickSize->insert(1, yBrickSize);
+ brickSize->insert(2, zBrickSize);
+ shared_ptr<XdmfArray> numPoints = XdmfArray::New();
+ numPoints->initialize<unsigned int>(3);
+ numPoints->insert(0, xNumPoints);
+ numPoints->insert(1, yNumPoints);
+ numPoints->insert(2, zNumPoints);
+ shared_ptr<XdmfArray> origin = XdmfArray::New();
+ origin->initialize<double>(3);
+ origin->insert(0, xOrigin);
+ origin->insert(1, yOrigin);
+ origin->insert(2, zOrigin);
+ shared_ptr<XdmfRegularGrid> p(new XdmfRegularGrid(brickSize,
+ numPoints,
+ origin));
+ return p;
+}
+
+shared_ptr<XdmfRegularGrid>
+XdmfRegularGrid::New(const shared_ptr<XdmfArray> brickSize,
+ const shared_ptr<XdmfArray> numPoints,
+ const shared_ptr<XdmfArray> origin)
+{
+ shared_ptr<XdmfRegularGrid> p(new XdmfRegularGrid(brickSize,
+ numPoints,
+ origin));
+ return p;
+}
+
+XdmfRegularGrid::XdmfRegularGrid(const shared_ptr<XdmfArray> brickSize,
+ const shared_ptr<XdmfArray> numPoints,
+ const shared_ptr<XdmfArray> origin) :
+ XdmfGrid(XdmfRegularGridImpl::XdmfGeometryRegular::New(this),
+ XdmfRegularGridImpl::XdmfTopologyRegular::New(this))
+{
+ mImpl = new XdmfRegularGridImpl(brickSize, numPoints, origin);
+}
+
+XdmfRegularGrid::XdmfRegularGrid(XdmfRegularGrid & refGrid) :
+ XdmfGrid(refGrid)
+{
+ mGeometry = XdmfRegularGridImpl::XdmfGeometryRegular::New(this);
+ mTopology = XdmfRegularGridImpl::XdmfTopologyRegular::New(this);
+}
+
+XdmfRegularGrid::~XdmfRegularGrid()
+{
+ if (mImpl) {
+ delete mImpl;
+ }
+ mImpl = NULL;
+}
+
+const std::string XdmfRegularGrid::ItemTag = "Grid";
+
+void
+XdmfRegularGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
+{
+ XdmfGrid::copyGrid(sourceGrid);
+ if (shared_ptr<XdmfRegularGrid> classedGrid = shared_dynamic_cast<XdmfRegularGrid>(sourceGrid))
+ {
+ // Copy stucture from read grid to this grid
+ this->setOrigin(classedGrid->getOrigin());
+ this->setDimensions(classedGrid->getDimensions());
+ this->setBrickSize(classedGrid->getBrickSize());
+ }
+}
+
+shared_ptr<XdmfArray>
+XdmfRegularGrid::getBrickSize()
+{
+ return boost::const_pointer_cast<XdmfArray>
+ (static_cast<const XdmfRegularGrid &>(*this).getBrickSize());
+}
+
+shared_ptr<const XdmfArray>
+XdmfRegularGrid::getBrickSize() const
+{
+ return ((XdmfRegularGridImpl *)mImpl)->mBrickSize;
+}
+
+shared_ptr<XdmfArray>
+XdmfRegularGrid::getDimensions()
+{
+ return boost::const_pointer_cast<XdmfArray>
+ (static_cast<const XdmfRegularGrid &>(*this).getDimensions());
+}
+
+shared_ptr<const XdmfArray>
+XdmfRegularGrid::getDimensions() const
+{
+ return ((XdmfRegularGridImpl *)mImpl)->mDimensions;
+}
+
+shared_ptr<XdmfArray>
+XdmfRegularGrid::getOrigin()
+{
+ return boost::const_pointer_cast<XdmfArray>
+ (static_cast<const XdmfRegularGrid &>(*this).getOrigin());
+}
+
+shared_ptr<const XdmfArray>
+XdmfRegularGrid::getOrigin() const
+{
+ return ((XdmfRegularGridImpl *)mImpl)->mOrigin;
+}
+
+void
+XdmfRegularGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfGrid::populateItem(itemProperties, childItems, reader);
+
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfRegularGrid> regularGrid =
+ shared_dynamic_cast<XdmfRegularGrid>(*iter)) {
+ if(regularGrid->getBrickSize()) {
+ ((XdmfRegularGridImpl *)mImpl)->mBrickSize = regularGrid->getBrickSize();
+ }
+
+ if(regularGrid->getDimensions()) {
+ ((XdmfRegularGridImpl *)mImpl)->mDimensions = regularGrid->getDimensions();
+ }
+
+ if(regularGrid->getOrigin()) {
+ ((XdmfRegularGridImpl *)mImpl)->mOrigin = regularGrid->getOrigin();
+ }
+ }
+ }
+}
+
+void
+XdmfRegularGrid::read()
+{
+ if (mGridController)
+ {
+ if (shared_ptr<XdmfRegularGrid> grid = shared_dynamic_cast<XdmfRegularGrid>(mGridController->read()))
+ {
+ // Copy stucture from read grid to this grid
+ copyGrid(grid);
+ }
+ else if (shared_dynamic_cast<XdmfGrid>(mGridController->read()))
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference");
+ }
+ }
+}
+
+void
+XdmfRegularGrid::release()
+{
+ XdmfGrid::release();
+ this->setOrigin(shared_ptr<XdmfArray>());
+ this->setDimensions(shared_ptr<XdmfArray>());
+ this->setBrickSize(shared_ptr<XdmfArray>());
+}
+
+void
+XdmfRegularGrid::setBrickSize(const shared_ptr<XdmfArray> brickSize)
+{
+ ((XdmfRegularGridImpl *)mImpl)->mBrickSize = brickSize;
+ this->setIsChanged(true);
+}
+
+void
+XdmfRegularGrid::setDimensions(const shared_ptr<XdmfArray> dimensions)
+{
+ ((XdmfRegularGridImpl *)mImpl)->mDimensions = dimensions;
+ this->setIsChanged(true);
+}
+
+void
+XdmfRegularGrid::setOrigin(const shared_ptr<XdmfArray> origin)
+{
+ ((XdmfRegularGridImpl *)mImpl)->mOrigin = origin;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+XDMFREGULARGRID * XdmfRegularGridNew2D(double xBrickSize,
+ double yBrickSize,
+ unsigned int xNumPoints,
+ unsigned int yNumPoints,
+ double xOrigin,
+ double yOrigin)
+{
+ try
+ {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(xBrickSize,
+ yBrickSize,
+ xNumPoints,
+ yNumPoints,
+ xOrigin,
+ yOrigin);
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(xBrickSize,
+ yBrickSize,
+ xNumPoints,
+ yNumPoints,
+ xOrigin,
+ yOrigin);
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+}
+
+XDMFREGULARGRID * XdmfRegularGridNew3D(double xBrickSize,
+ double yBrickSize,
+ double zBrickSize,
+ unsigned int xNumPoints,
+ unsigned int yNumPoints,
+ unsigned int zNumPoints,
+ double xOrigin,
+ double yOrigin,
+ double zOrigin)
+{
+ try
+ {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(xBrickSize,
+ yBrickSize,
+ zBrickSize,
+ xNumPoints,
+ yNumPoints,
+ zNumPoints,
+ xOrigin,
+ yOrigin,
+ zOrigin);
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(xBrickSize,
+ yBrickSize,
+ zBrickSize,
+ xNumPoints,
+ yNumPoints,
+ zNumPoints,
+ xOrigin,
+ yOrigin,
+ zOrigin);
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+}
+
+XDMFREGULARGRID * XdmfRegularGridNew(XDMFARRAY * brickSize,
+ XDMFARRAY * numPoints,
+ XDMFARRAY * origin,
+ int passControl)
+{
+ try
+ {
+ if (passControl) {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(shared_ptr<XdmfArray>((XdmfArray *)brickSize),
+ shared_ptr<XdmfArray>((XdmfArray *)numPoints),
+ shared_ptr<XdmfArray>((XdmfArray *)origin));
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+ else {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(shared_ptr<XdmfArray>((XdmfArray *)brickSize, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)numPoints, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)origin, XdmfNullDeleter()));
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+ }
+ catch (...)
+ {
+ if (passControl) {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(shared_ptr<XdmfArray>((XdmfArray *)brickSize),
+ shared_ptr<XdmfArray>((XdmfArray *)numPoints),
+ shared_ptr<XdmfArray>((XdmfArray *)origin));
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+ else {
+ shared_ptr<XdmfRegularGrid> generatedGrid = XdmfRegularGrid::New(shared_ptr<XdmfArray>((XdmfArray *)brickSize, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)numPoints, XdmfNullDeleter()),
+ shared_ptr<XdmfArray>((XdmfArray *)origin, XdmfNullDeleter()));
+ return (XDMFREGULARGRID *)((void *)((XdmfItem *)(new XdmfRegularGrid(*generatedGrid.get()))));
+ }
+ }
+}
+
+XDMFARRAY * XdmfRegularGridGetBrickSize(XDMFREGULARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRegularGrid * gridPointer = dynamic_cast<XdmfRegularGrid *>(classedPointer);
+ shared_ptr<XdmfArray> generatedBrick = gridPointer->getBrickSize();
+ return (XDMFARRAY *)((void *)(generatedBrick.get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfRegularGridGetDimensions(XDMFREGULARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRegularGrid * gridPointer = dynamic_cast<XdmfRegularGrid *>(classedPointer);
+ shared_ptr<XdmfArray> generatedDimensions = gridPointer->getDimensions();
+ return (XDMFARRAY *)((void *)(generatedDimensions.get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfRegularGridGetOrigin(XDMFREGULARGRID * grid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRegularGrid * gridPointer = dynamic_cast<XdmfRegularGrid *>(classedPointer);
+ shared_ptr<XdmfArray> generatedOrigin = gridPointer->getOrigin();
+ return (XDMFARRAY *)((void *)(generatedOrigin.get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void XdmfRegularGridSetBrickSize(XDMFREGULARGRID * grid, XDMFARRAY * brickSize, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRegularGrid * gridPointer = dynamic_cast<XdmfRegularGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setBrickSize(shared_ptr<XdmfArray>((XdmfArray *)brickSize));
+ }
+ else {
+ gridPointer->setBrickSize(shared_ptr<XdmfArray>((XdmfArray *)brickSize, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfRegularGridSetDimensions(XDMFREGULARGRID * grid, XDMFARRAY * dimensions, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRegularGrid * gridPointer = dynamic_cast<XdmfRegularGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setDimensions(shared_ptr<XdmfArray>((XdmfArray *)dimensions));
+ }
+ else {
+ gridPointer->setDimensions(shared_ptr<XdmfArray>((XdmfArray *)dimensions, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfRegularGridSetOrigin(XDMFREGULARGRID * grid, XDMFARRAY * origin, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfItem * classedPointer = (XdmfItem *)grid;
+ XdmfRegularGrid * gridPointer = dynamic_cast<XdmfRegularGrid *>(classedPointer);
+ if (passControl) {
+ gridPointer->setOrigin(shared_ptr<XdmfArray>((XdmfArray *)origin));
+ }
+ else {
+ gridPointer->setOrigin(shared_ptr<XdmfArray>((XdmfArray *)origin, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfRegularGrid, XDMFREGULARGRID)
+XDMF_GRID_C_CHILD_WRAPPER(XdmfRegularGrid, XDMFREGULARGRID)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfRegularGrid.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFREGULARGRID_HPP_
+#define XDMFREGULARGRID_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfGrid.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+/**
+ * @brief A regular grid consists of congruent points arranged
+ * regularly in space.
+ *
+ * XdmfRegularGrid represents a regular mesh of congruent points
+ * arranged in space. In order to define a regular grid, three sets of
+ * terms need to be supplied:
+ *
+ * Brick Size (Dx, Dy, (Dz)) - Size of an individual brick.
+ * Dimensions (X, Y, (Z)) - Number of points in X, Y, and Z directions
+ * Origin Location (X, Y, (Z)) - Location of the origin of the mesh in space.
+ */
+class XDMF_EXPORT XdmfRegularGrid : public XdmfGrid {
+
+public:
+
+ /**
+ * Create a new structured grid (Two dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initvalue
+ * @until #//initvalue
+ * @skipline #//initialization2
+ * @until #//initialization2
+ *
+ * @param xBrickSize The size of the brick in the x direction.
+ * @param yBrickSize The size of the brick in the y direction.
+ * @param xNumPoints The number of points in the x direction.
+ * @param yNumPoints The number of points in the y direction.
+ * @param xOrigin The x coordinate of the origin.
+ * @param yOrigin The y coordinate of the origin.
+ *
+ * @return Constructed structured grid.
+ */
+ static shared_ptr<XdmfRegularGrid> New(const double xBrickSize,
+ const double yBrickSize,
+ const unsigned int xNumPoints,
+ const unsigned int yNumPoints,
+ const double xOrigin,
+ const double yOrigin);
+
+ /**
+ * Create a new structured grid (Three dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization3
+ * @until //#initialization3
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initvalue
+ * @until #//initvalue
+ * @skipline #//initialization3
+ * @until #//initialization3
+ *
+ * @param xBrickSize The size of the brick in the x direction.
+ * @param yBrickSize The size of the brick in the y direction.
+ * @param zBrickSize The size of the brick in the z direction.
+ * @param xNumPoints The number of points in the x direction.
+ * @param yNumPoints The number of points in the y direction.
+ * @param zNumPoints The number of points in the z direction.
+ * @param xOrigin The x coordinate of the origin.
+ * @param yOrigin The y coordinate of the origin.
+ * @param zOrigin The z coordinate of the origin.
+ *
+ * @return Constructed structured grid.
+ */
+ static shared_ptr<XdmfRegularGrid> New(const double xBrickSize,
+ const double yBrickSize,
+ const double zBrickSize,
+ const unsigned int xNumPoints,
+ const unsigned int yNumPoints,
+ const unsigned int zNumPoints,
+ const double xOrigin,
+ const double yOrigin,
+ const double zOrigin);
+
+ /**
+ * Create a new structured grid (N dimensional).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ *
+ * @param brickSize The size of the brick in each direction.
+ * @param numPoints The number of points in each direction.
+ * @param origin The coordinates of the origin.
+ *
+ * @return Constructed structured grid.
+ */
+ static shared_ptr<XdmfRegularGrid>
+ New(const shared_ptr<XdmfArray> brickSize,
+ const shared_ptr<XdmfArray> numPoints,
+ const shared_ptr<XdmfArray> origin);
+
+ virtual ~XdmfRegularGrid();
+
+ LOKI_DEFINE_VISITABLE(XdmfRegularGrid, XdmfGrid)
+ static const std::string ItemTag;
+
+ /**
+ * Get the size of the bricks composing the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getBrickSize
+ * @until //#getBrickSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initvalue
+ * @until #//initvalue
+ * @skipline #//initialization2
+ * @until #//initialization2
+ * @skipline #//getBrickSize
+ * @until #//getBrickSize
+ *
+ * @return XdmfArray containing brick sizes for this grid.
+ */
+ shared_ptr<XdmfArray> getBrickSize();
+
+ /**
+ * Get the size of the bricks composing the grid (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getBrickSizeconst
+ * @until //#getBrickSizeconst
+ *
+ * Python: Does not support a constant version of this function
+ *
+ * @return XdmfArray containing brick sizes for this grid.
+ */
+ shared_ptr<const XdmfArray> getBrickSize() const;
+
+ /**
+ * Get the dimensions of the grid, the number of points in each
+ * direction.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initvalue
+ * @until #//initvalue
+ * @skipline #//initialization2
+ * @until #//initialization2
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return XdmfArray containing dimensions of this grid.
+ */
+ shared_ptr<XdmfArray> getDimensions();
+
+ /**
+ * Get the dimensions of the grid, the number of points in each
+ * direction (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getDimensionsconst
+ * @until //#getDimensionsconst
+ *
+ * Python: Does not support a constant version of this function
+ *
+ * @return XdmfArray containing the dimensions of this grid.
+ */
+ shared_ptr<const XdmfArray> getDimensions() const;
+
+ /**
+ * Get the location of the origin of the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getOrigin
+ * @until //#getOrigin
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initvalue
+ * @until #//initvalue
+ * @skipline #//initialization2
+ * @until #//initialization2
+ * @skipline #//getOrigin
+ * @until #//getOrigin
+ *
+ * @return XdmfArray containing the location of the origin of the
+ * grid.
+ */
+ shared_ptr<XdmfArray> getOrigin();
+
+ /**
+ * Get the location of the origin of the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initvalue
+ * @until //#initvalue
+ * @skipline //#initialization2
+ * @until //#initialization2
+ * @skipline //#getOriginconst
+ * @until //#getOriginconst
+ *
+ * Python: Does not support a constant version of this function
+ *
+ * @return XdmfArray containing the location of the origin of the
+ * grid (const version).
+ */
+ shared_ptr<const XdmfArray> getOrigin() const;
+
+ virtual void read();
+
+ virtual void release();
+
+ /**
+ * Set the size of the points composing the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#setBrickSize
+ * @until //#setBrickSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ * @skipline #//setBrickSize
+ * @until #//setBrickSize
+ *
+ * @param brickSize The sizes of the points composing the mesh. This
+ * should have the same number of terms as the
+ * dimensionality of the mesh.
+ */
+ void setBrickSize(const shared_ptr<XdmfArray> brickSize);
+
+ /**
+ * Set the dimensions of the grid, the number of points in each
+ * direction.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#setDimensions
+ * @until //#setDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ * @skipline #//setDimensions
+ * @until #//setDimensions
+ *
+ * @param dimensions The dimension of the grid.
+ */
+ void setDimensions(const shared_ptr<XdmfArray> dimensions);
+
+ /**
+ * Set the origin of the grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfRegularGrid.cpp
+ * @skipline //#initializationvector
+ * @until //#initializationvector
+ * @skipline //#setOrigin
+ * @until //#setOrigin
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleRegularGrid.py
+ * @skipline #//initializationvector
+ * @until #//initializationvector
+ * @skipline #//setOrigin
+ * @until #//setOrigin
+ *
+ * @param origin Location of the origin of the grid. This should
+ * have the same number of terms as the dimensionality
+ * of the mesh.
+ */
+ void setOrigin(const shared_ptr<XdmfArray> origin);
+
+ XdmfRegularGrid(XdmfRegularGrid &);
+
+protected:
+
+ XdmfRegularGrid(const shared_ptr<XdmfArray> brickSize,
+ const shared_ptr<XdmfArray> numPoints,
+ const shared_ptr<XdmfArray> origin);
+
+ virtual void
+ copyGrid(shared_ptr<XdmfGrid> sourceGrid);
+
+ void populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfRegularGridImpl;
+
+ XdmfRegularGrid(const XdmfRegularGrid &); // Not implemented.
+ void operator=(const XdmfRegularGrid &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFREGULARGRID; // Simply as a typedef to ensure correct typing
+typedef struct XDMFREGULARGRID XDMFREGULARGRID;
+
+XDMF_EXPORT XDMFREGULARGRID * XdmfRegularGridNew2D(double xBrickSize,
+ double yBrickSize,
+ unsigned int xNumPoints,
+ unsigned int yNumPoints,
+ double xOrigin,
+ double yOrigin);
+
+XDMF_EXPORT XDMFREGULARGRID * XdmfRegularGridNew3D(double xBrickSize,
+ double yBrickSize,
+ double zBrickSize,
+ unsigned int xNumPoints,
+ unsigned int yNumPoints,
+ unsigned int zNumPoints,
+ double xOrigin,
+ double yOrigin,
+ double zOrigin);
+
+XDMF_EXPORT XDMFREGULARGRID * XdmfRegularGridNew(XDMFARRAY * brickSize,
+ XDMFARRAY * numPoints,
+ XDMFARRAY * origin,
+ int passControl);
+
+XDMF_EXPORT XDMFARRAY * XdmfRegularGridGetBrickSize(XDMFREGULARGRID * grid, int * status);
+
+XDMF_EXPORT XDMFARRAY * XdmfRegularGridGetDimensions(XDMFREGULARGRID * grid, int * status);
+
+XDMF_EXPORT XDMFARRAY * XdmfRegularGridGetOrigin(XDMFREGULARGRID * grid, int * status);
+
+XDMF_EXPORT void XdmfRegularGridSetBrickSize(XDMFREGULARGRID * grid, XDMFARRAY * brickSize, int passControl, int * status);
+
+XDMF_EXPORT void XdmfRegularGridSetDimensions(XDMFREGULARGRID * grid, XDMFARRAY * dimensions, int passControl, int * status);
+
+XDMF_EXPORT void XdmfRegularGridSetOrigin(XDMFREGULARGRID * grid, XDMFARRAY * origin, int passControl, int * status);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfRegularGrid, XDMFREGULARGRID, XDMF)
+XDMF_GRID_C_CHILD_DECLARE(XdmfRegularGrid, XDMFREGULARGRID, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFREGULARGRID_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSet.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfAttribute.hpp"
+#include "XdmfHDF5Controller.hpp"
+#include "XdmfSet.hpp"
+#include "XdmfSetType.hpp"
+#include "XdmfError.hpp"
+
+#include <sstream>
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfSet, XdmfAttribute, Attribute, Name)
+
+ shared_ptr<XdmfSet>
+XdmfSet::New()
+{
+ shared_ptr<XdmfSet> p(new XdmfSet());
+ return p;
+}
+
+XdmfSet::XdmfSet() :
+ mName(""),
+ mType(XdmfSetType::NoSetType())
+{
+}
+
+XdmfSet::XdmfSet(XdmfSet & refSet) :
+ XdmfArray(refSet),
+ mName(refSet.mName),
+ mType(refSet.mType)
+{
+}
+
+XdmfSet::~XdmfSet()
+{
+}
+
+const std::string XdmfSet::ItemTag = "Set";
+
+std::map<std::string, std::string>
+XdmfSet::getItemProperties() const
+{
+ std::map<std::string, std::string> setProperties;
+ setProperties.insert(std::make_pair("Name", mName));
+ mType->getProperties(setProperties);
+ return setProperties;
+}
+
+std::string
+XdmfSet::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::string
+XdmfSet::getName() const
+{
+ return mName;
+}
+
+shared_ptr<const XdmfSetType>
+XdmfSet::getType() const
+{
+ return mType;
+}
+
+void
+XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ std::map<std::string, std::string>::const_iterator name =
+ itemProperties.find("Name");
+ if(name != itemProperties.end()) {
+ mName = name->second;
+ }
+ mType = XdmfSetType::New(itemProperties);
+ bool filled = false;
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfAttribute> attribute =
+ shared_dynamic_cast<XdmfAttribute>(*iter)) {
+ this->insert(attribute);
+ }
+ else if(shared_ptr<XdmfArray> array =
+ shared_dynamic_cast<XdmfArray>(*iter)) {
+ if (!filled) {
+ this->swap(array);
+ filled = true;
+ }
+ if (array->getReference()) {
+ this->setReference(array->getReference());
+ this->setReadMode(XdmfArray::Reference);
+ }
+ // TODO: If multiple dataitems.
+ }
+ }
+}
+
+void
+XdmfSet::setName(const std::string & name)
+{
+ mName = name;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSet::setType(const shared_ptr<const XdmfSetType> type)
+{
+ mType = type;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSet::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+ for (unsigned int i = 0; i < mAttributes.size(); ++i)
+ {
+ mAttributes[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+XDMFSET * XdmfSetNew()
+{
+ try
+ {
+ shared_ptr<XdmfSet> generatedSet = XdmfSet::New();
+ return (XDMFSET*)((void *)(new XdmfSet(*generatedSet.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfSet> generatedSet = XdmfSet::New();
+ return (XDMFSET*)((void *)(new XdmfSet(*generatedSet.get())));
+ }
+}
+
+XDMFATTRIBUTE * XdmfSetGetAttribute(XDMFSET * set, unsigned int index)
+{
+ return (XDMFATTRIBUTE *)((void *)(((XdmfSet *)(set))->getAttribute(index).get()));
+}
+
+XDMFATTRIBUTE * XdmfSetGetAttributeByName(XDMFSET * set, char * Name)
+{
+ return (XDMFATTRIBUTE *)((void *)(((XdmfSet *)(set))->getAttribute(Name).get()));
+}
+
+unsigned int XdmfSetGetNumberAttributes(XDMFSET * set)
+{
+ return ((XdmfSet *)(set))->getNumberAttributes();
+}
+
+int XdmfSetGetType(XDMFSET * set)
+{
+ shared_ptr<const XdmfSetType> checkType = ((XdmfSet *)set)->getType();
+
+ if (checkType == XdmfSetType::NoSetType()) {
+ return XDMF_SET_TYPE_NO_SET_TYPE;
+ }
+ else if (checkType == XdmfSetType::Node()) {
+ return XDMF_SET_TYPE_NODE;
+ }
+ else if (checkType == XdmfSetType::Cell()) {
+ return XDMF_SET_TYPE_CELL;
+ }
+ else if (checkType == XdmfSetType::Face()) {
+ return XDMF_SET_TYPE_FACE;
+ }
+ else if (checkType == XdmfSetType::Edge()) {
+ return XDMF_SET_TYPE_EDGE;
+ }
+ else {
+ return -1;
+ }
+}
+
+void XdmfSetInsertAttribute(XDMFSET * set, XDMFATTRIBUTE * Attribute, int passControl)
+{
+ if (passControl) {
+ ((XdmfSet *)(set))->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute));
+ }
+ else {
+ ((XdmfSet *)(set))->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute, XdmfNullDeleter()));
+ }
+}
+
+void XdmfSetRemoveAttribute(XDMFSET * set, unsigned int index)
+{
+ ((XdmfSet *)(set))->removeAttribute(index);
+}
+
+void XdmfSetRemoveAttributeByName(XDMFSET * set, char * Name)
+{
+ ((XdmfSet *)(set))->removeAttribute(Name);
+}
+
+void XdmfSetSetType(XDMFSET * set, int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<const XdmfSetType> newType = shared_ptr<const XdmfSetType>();
+ switch (type) {
+ case XDMF_SET_TYPE_NO_SET_TYPE:
+ newType = XdmfSetType::NoSetType();
+ break;
+ case XDMF_SET_TYPE_NODE:
+ newType = XdmfSetType::Node();
+ break;
+ case XDMF_SET_TYPE_CELL:
+ newType = XdmfSetType::Cell();
+ break;
+ case XDMF_SET_TYPE_FACE:
+ newType = XdmfSetType::Face();
+ break;
+ case XDMF_SET_TYPE_EDGE:
+ newType = XdmfSetType::Edge();
+ break;
+ default:
+ {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Set Type: Code " << type;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ break;
+ }
+ ((XdmfSet *)set)->setType(newType);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfSet, XDMFSET)
+XDMF_ARRAY_C_CHILD_WRAPPER(XdmfSet, XDMFSET)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSet.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFSET_HPP_
+#define XDMFSET_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfAttribute.hpp"
+#include "XdmfSetType.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfAttribute;
+class XdmfHDF5Controller;
+
+/**
+ * @brief Holds a collection of individual nodes, cells, faces, or
+ * edges that are part of an XdmfGrid.
+ *
+ * An XdmfSet holds a collection of nodes, cells, faces, or edges that
+ * are part of an XdmfGrid. For instance, a simulation may want to
+ * hold a set of nodes on a boundary. The individual elements making
+ * up the set are determined by their id. An XdmfSet can have
+ * XdmfAttributes attached that contain extra values attached to the
+ * elements in the set.
+ */
+class XDMF_EXPORT XdmfSet : public XdmfArray {
+
+public:
+
+ /**
+ * Create a new XdmfSet.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSet.cpp
+ * @skipline //#initialize
+ * @until //#initialize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSet.py
+ * @skipline #//initialize
+ * @until #//initialize
+ *
+ * @return Constructed XdmfSet.
+ */
+ static shared_ptr<XdmfSet> New();
+
+ virtual ~XdmfSet();
+
+ LOKI_DEFINE_VISITABLE(XdmfSet, XdmfArray)
+ XDMF_CHILDREN(XdmfSet, XdmfAttribute, Attribute, Name)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the name of the set.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSet.cpp
+ * @skipline //#initialize
+ * @until //#initialize
+ * @skipline //#setName
+ * @until //#setName
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSet.py
+ * @skipline #//initialize
+ * @until #//initialize
+ * @skipline #//setName
+ * @until #//setName
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return A string containing the name of the set.
+ */
+ std::string getName() const;
+
+ /**
+ * Get the XdmfSetType associated with this set.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSet.cpp
+ * @skipline //#initialize
+ * @until //#initialize
+ * @skipline //#setType
+ * @until //#setType
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSet.py
+ * @skipline #//initialize
+ * @until #//initialize
+ * @skipline #//setType
+ * @until #//setType
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * @return XdmfSetType of this set.
+ */
+ shared_ptr<const XdmfSetType> getType() const;
+
+ using XdmfArray::insert;
+
+#if defined(SWIG)
+ using XdmfItem::insert;
+#endif
+
+ /**
+ * Set the name of the set.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSet.cpp
+ * @skipline //#initialize
+ * @until //#initialize
+ * @skipline //#setName
+ * @until //#setName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSet.py
+ * @skipline #//initialize
+ * @until #//initialize
+ * @skipline #//setName
+ * @until #//setName
+ *
+ * @param name A string containing the name to set.
+ */
+ void setName(const std::string & name);
+
+ /**
+ * Set the XdmfSetType associated with this set.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSet.cpp
+ * @skipline //#initialize
+ * @until //#initialize
+ * @skipline //#setType
+ * @until //#setType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSet.py
+ * @skipline //#initialize
+ * @until //#initialize
+ * @skipline //#setType
+ * @until //#setType
+ *
+ * @param type The XdmfSetType to set.
+ */
+ void setType(const shared_ptr<const XdmfSetType> type);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfSet(XdmfSet &);
+
+protected:
+
+ XdmfSet();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfSet(const XdmfSet &);
+ void operator=(const XdmfSet &); // Not implemented.
+
+ std::string mName;
+ shared_ptr<const XdmfSetType> mType;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFSET; // Simply as a typedef to ensure correct typing
+typedef struct XDMFSET XDMFSET;
+
+XDMF_EXPORT XDMFSET * XdmfSetNew();
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfSetGetAttribute(XDMFSET * set, unsigned int index);
+
+XDMF_EXPORT XDMFATTRIBUTE * XdmfSetGetAttributeByName(XDMFSET * set, char * Name);
+
+XDMF_EXPORT unsigned int XdmfSetGetNumberAttributes(XDMFSET * set);
+
+XDMF_EXPORT int XdmfSetGetType(XDMFSET * set);
+
+XDMF_EXPORT void XdmfSetInsertAttribute(XDMFSET * set, XDMFATTRIBUTE * Attribute, int passControl);
+
+XDMF_EXPORT void XdmfSetRemoveAttribute(XDMFSET * set, unsigned int index);
+
+XDMF_EXPORT void XdmfSetRemoveAttributeByName(XDMFSET * set, char * Name);
+
+XDMF_EXPORT void XdmfSetSetType(XDMFSET * set, int type, int * status);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfSet, XDMFSET, XDMF)
+XDMF_ARRAY_C_CHILD_DECLARE(XdmfSet, XDMFSET, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFSET_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSetType.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "XdmfSetType.hpp"
+#include "XdmfError.hpp"
+
+std::map<std::string, shared_ptr<const XdmfSetType>(*)()> XdmfSetType::mSetDefinitions;
+
+// Supported XdmfSetTypes
+shared_ptr<const XdmfSetType>
+XdmfSetType::NoSetType()
+{
+ static shared_ptr<const XdmfSetType> p(new XdmfSetType("None"));
+ return p;
+}
+
+shared_ptr<const XdmfSetType>
+XdmfSetType::Node()
+{
+ static shared_ptr<const XdmfSetType> p(new XdmfSetType("Node"));
+ return p;
+}
+
+shared_ptr<const XdmfSetType>
+XdmfSetType::Cell()
+{
+ static shared_ptr<const XdmfSetType> p(new XdmfSetType("Cell"));
+ return p;
+}
+
+shared_ptr<const XdmfSetType>
+XdmfSetType::Face()
+{
+ static shared_ptr<const XdmfSetType> p(new XdmfSetType("Face"));
+ return p;
+}
+
+shared_ptr<const XdmfSetType>
+XdmfSetType::Edge()
+{
+ static shared_ptr<const XdmfSetType> p(new XdmfSetType("Edge"));
+ return p;
+}
+
+void
+XdmfSetType::InitTypes()
+{
+ mSetDefinitions["NONE"] = NoSetType;
+ mSetDefinitions["NODE"] = Node;
+ mSetDefinitions["CELL"] = Cell;
+ mSetDefinitions["FACE"] = Face;
+ mSetDefinitions["EDGE"] = Edge;
+}
+
+XdmfSetType::XdmfSetType(const std::string & name) :
+ mName(name)
+{
+}
+
+XdmfSetType::~XdmfSetType()
+{
+}
+
+shared_ptr<const XdmfSetType>
+XdmfSetType::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("SetType");
+ }
+ if(type == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Neither 'Type' nor 'SetType' found in itemProperties "
+ "in XdmfSetType::New");
+ }
+ const std::string & typeVal = ConvertToUpper(type->second);
+
+ std::map<std::string, shared_ptr<const XdmfSetType>(*)()>::const_iterator returnType
+ = mSetDefinitions.find(typeVal);
+
+ if (returnType == mSetDefinitions.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Type not of 'None', 'Node', 'Cell', 'Face', or "
+ "'Edge' in XdmfSetType::New");
+ }
+ else {
+ return (*(returnType->second))();
+ }
+
+ XdmfError::message(XdmfError::FATAL,
+ "Type not of 'None', 'Node', 'Cell', 'Face', or "
+ "'Edge' in XdmfSetType::New");
+
+ // unreachable
+ return shared_ptr<const XdmfSetType>();
+}
+
+void
+XdmfSetType::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("Type", mName));
+}
+
+// C Wrappers
+
+int XdmfSetTypeNoSetType()
+{
+ return XDMF_SET_TYPE_NO_SET_TYPE;
+}
+
+int XdmfSetTypeNode()
+{
+ return XDMF_SET_TYPE_NODE;
+}
+
+int XdmfSetTypeCell()
+{
+ return XDMF_SET_TYPE_CELL;
+}
+
+int XdmfSetTypeFace()
+{
+ return XDMF_SET_TYPE_FACE;
+}
+
+int XdmfSetTypeEdge()
+{
+ return XDMF_SET_TYPE_EDGE;
+}
--- /dev/null
+#ifndef XDMFSETTYPE_HPP_
+#define XDMFSETTYPE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include "XdmfItemProperty.hpp"
+
+/**
+ * @brief Property describing the type of ids an XdmfSet contains.
+ *
+ * An XdmfSet holds ids for a collection of nodes, cells, faces, or
+ * edges that are part of an XdmfGrid. This property indicates which
+ * type the set contains.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSet.cpp
+ * @skipline //#initialize
+ * @until //#initialize
+ * @skipline //#setType
+ * @until //#setType
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSet.py
+ * @skipline #//initialize
+ * @until #//initialize
+ * @skipline #//setType
+ * @until #//setType
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * Xdmf supports the following set types:
+ * NoSetType
+ * Node
+ * Cell
+ * Face
+ * Edge
+ */
+class XDMF_EXPORT XdmfSetType : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfSetType();
+
+ friend class XdmfSet;
+
+ // Supported Xdmf Set Types
+ static shared_ptr<const XdmfSetType> NoSetType();
+ static shared_ptr<const XdmfSetType> Node();
+ static shared_ptr<const XdmfSetType> Cell();
+ static shared_ptr<const XdmfSetType> Face();
+ static shared_ptr<const XdmfSetType> Edge();
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+protected:
+
+ /**
+ * Protected constructor for XdmfSetType. The constructor is
+ * protected because all set types supported by Xdmf should be
+ * accessed through more specific static methods that construct
+ * XdmfSetTypes - i.e. XdmfSetType::Node().
+ *
+ * @param name A std::string containing the name of the XdmfSetType.
+ */
+ XdmfSetType(const std::string & name);
+
+ static std::map<std::string, shared_ptr<const XdmfSetType>(*)()> mSetDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfSetType(const XdmfSetType &); // Not implemented.
+ void operator=(const XdmfSetType &); // Not implemented.
+
+ static shared_ptr<const XdmfSetType>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ std::string mName;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#define XDMF_SET_TYPE_NO_SET_TYPE 600
+#define XDMF_SET_TYPE_NODE 601
+#define XDMF_SET_TYPE_CELL 602
+#define XDMF_SET_TYPE_FACE 603
+#define XDMF_SET_TYPE_EDGE 604
+
+XDMF_EXPORT int XdmfSetTypeNoSetType();
+XDMF_EXPORT int XdmfSetTypeNode();
+XDMF_EXPORT int XdmfSetTypeCell();
+XDMF_EXPORT int XdmfSetTypeFace();
+XDMF_EXPORT int XdmfSetTypeEdge();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFSETTYPE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTemplate.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <sstream>
+#include <utility>
+#include <climits>
+#include <set>
+#include "XdmfArray.hpp"
+#include "XdmfHDF5Controller.hpp"
+#include "XdmfBinaryController.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfItemFactory.hpp"
+#include "XdmfReader.hpp"
+#include "XdmfTemplate.hpp"
+#include "XdmfError.hpp"
+#include "XdmfVisitor.hpp"
+#include "XdmfWriter.hpp"
+
+#include "XdmfSystemUtils.hpp"
+
+#include <boost/tokenizer.hpp>
+
+#include <stdio.h>
+
+std::vector<shared_ptr<XdmfHeavyDataController> >
+getStepControllers(unsigned int stepId,
+ std::vector<unsigned int> stepDims,
+ std::vector<shared_ptr<XdmfHeavyDataController> > datasetControllers)
+{
+ std::vector<shared_ptr<XdmfHeavyDataController> > returnVector;
+ if (datasetControllers.size() > 0)
+ {
+ unsigned int sizePerStep = 1;
+ for (unsigned int i = 0; i < stepDims.size(); ++i)
+ {
+ sizePerStep *= stepDims[i];
+ }
+// unsigned int offset = (sizePerStep * stepId);
+// unsigned int offsetStepsRemaining = 0;
+ unsigned int offset = 0;
+ unsigned int offsetStepsRemaining = stepId;
+ // grabbing the subset is a little different for each type
+ // Right now we assume controllers are of the same type
+ unsigned int controllerIndex = 0;
+ unsigned int sizeRemaining = sizePerStep;
+ unsigned int arrayoffset = 0;
+ while (sizeRemaining > 0)
+ {
+//printf("sizeRemaining = %u\n", sizeRemaining);
+ // We don't reset the controller index between runs of the while loop
+ // On iterations after the first it should only execute the loop once
+ // because offset is set to 0
+ while (controllerIndex < datasetControllers.size())
+ {
+//printf("offset = %u\n", offset);
+//printf("%u >= %u\n", offset, datasetControllers[controllerIndex]->getSize());
+ //Iterate until we find the controller that the step starts in
+ if (offset >= datasetControllers[controllerIndex]->getSize())
+ {
+ offset -= datasetControllers[controllerIndex]->getSize();
+ ++controllerIndex;
+ }
+ else
+ {
+ if (offsetStepsRemaining == 0)
+ {
+ // offset is within the current controller
+ break;
+ }
+ else
+ {
+ // There are steps left to offset
+//printf("accounting for step %d\n", offsetStepsRemaining);
+ offset += sizePerStep;
+ --offsetStepsRemaining;
+ }
+ }
+ }
+//printf("final offset = %u\n", offset);
+ std::vector<unsigned int> newDimVector;
+ std::vector<unsigned int> newStarts;
+//printf("after creating dim vector but before filling it\n");
+//printf("%d < %d\n", controllerIndex, datasetControllers.size());
+//printf("size left %d\n", sizeRemaining);
+ if (offset + sizeRemaining <= datasetControllers[controllerIndex]->getSize())
+ {
+//printf("step is entirely in the controller\n");
+ // step is entirely within this controller
+ newStarts.push_back(offset + datasetControllers[controllerIndex]->getStart()[0]); // TODO multidim version
+ newDimVector.push_back(sizeRemaining);
+ sizeRemaining = 0;
+ }
+ else
+ {
+//printf("step is partially in the controller\n");
+ if (controllerIndex + 1 >= datasetControllers.size()) {
+ // Error, step doesn't fit in the data set provided
+ XdmfError::message(XdmfError::FATAL, "Error: Step does not fit in data step provided");
+ }
+ // step is partially in this controller
+ newDimVector.push_back(sizeRemaining -
+ (sizeRemaining - (datasetControllers[controllerIndex]->getSize() - offset)));
+ newStarts.push_back(offset+datasetControllers[controllerIndex]->getStart()[0]); // TODO multidim version
+ sizeRemaining -= newDimVector[0];
+ }
+//printf("size for other controllers %d\n", sizeRemaining);
+//printf("before creating the new controller\n");
+ // Using the remaining space in the controller
+ // Slightly differen creation method for each controller
+ if (datasetControllers[0]->getName().compare("Binary") == 0) {
+ shared_ptr<XdmfBinaryController> createdController =
+ XdmfBinaryController::New(datasetControllers[0]->getFilePath(),
+ datasetControllers[0]->getType(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[0])->getEndian(),
+ newStarts[0],
+ newDimVector);
+ returnVector.push_back(createdController);
+ }
+ else if (datasetControllers[0]->getName().compare("HDF") == 0) {
+ // TODO
+ // The writer should only write to contiguous sets when in this mode.
+ // A user would need to do something custom to foul this up.
+ std::vector<unsigned int> newStrides;
+ newStrides.push_back(1);
+ shared_ptr<XdmfHDF5Controller> createdController =
+ XdmfHDF5Controller::New(datasetControllers[controllerIndex]->getFilePath(),
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataSetPath(),
+ datasetControllers[0]->getType(),
+ newStarts,
+ newStrides,
+ newDimVector,
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+//printf("after creating the new controller\n");
+ returnVector[returnVector.size()-1]->setArrayOffset(arrayoffset);
+ arrayoffset += returnVector[returnVector.size()-1]->getSize();
+ offset = 0;
+ ++controllerIndex;
+ // Starts at the beggining of the next controller
+ }
+ }
+/*
+printf("size of return vector = %d\n", returnVector.size());
+for (unsigned int i = 0; i < returnVector.size(); ++i)
+{
+ shared_ptr<XdmfHDF5Controller> currentController = shared_dynamic_cast<XdmfHDF5Controller>(returnVector[i]);
+assert(currentController);
+ printf("file = %s\n", currentController->getFilePath().c_str());
+ printf("dataset = %s\n", currentController->getDataSetPath().c_str());
+ printf("start = %u\n", currentController->getStart()[0]);
+ printf("dimension = %u\n", currentController->getDimensions()[0]);
+ printf("dataspace = %u\n", currentController->getDataspaceDimensions()[0]);
+}
+*/
+ return returnVector;
+}
+
+std::vector<shared_ptr<XdmfHeavyDataController> >
+getControllersExcludingStep(unsigned int stepId,
+ std::vector<unsigned int> stepDims,
+ std::vector<shared_ptr<XdmfHeavyDataController> > datasetControllers)
+{
+ std::vector<shared_ptr<XdmfHeavyDataController> > returnVector;
+ if (datasetControllers.size() > 0)
+ {
+ unsigned int sizePerStep = 1;
+ for (unsigned int i = 0; i < stepDims.size(); ++i)
+ {
+ sizePerStep *= stepDims[i];
+ }
+ unsigned int offset = sizePerStep * stepId;
+ unsigned int sizeRemaining = sizePerStep;
+//printf("base offset = %u\nstarting size remaining = %u\ncutting from %u controllers\n", offset, sizeRemaining, datasetControllers.size());
+ // grabbing the subset is a little different for each type
+ // Right now we assume controllers are of the same type
+ for (unsigned int controllerIndex = 0; controllerIndex < datasetControllers.size(); ++controllerIndex)
+ {
+//printf("offset = %u out of controller size %u\n", offset, datasetControllers[controllerIndex]->getSize());
+ if (offset >= datasetControllers[controllerIndex]->getSize())
+ {
+ // The removed step isn't in the controller provided
+ // Simply add it back into the return set
+ returnVector.push_back(datasetControllers[controllerIndex]);
+ // then subtract the size from the offset
+ offset -= datasetControllers[controllerIndex]->getSize();
+ }
+ else
+ {
+ // The removed step is inside the controller provided
+ if (offset > 0)
+ {
+//printf("removed step is inside this controller\n");
+ // If offset is greater than zero the controller has a section chopped off the front
+ std::vector<unsigned int> newDim;
+ newDim.push_back(offset);
+ // Dataspace is the same
+ // stride is the same
+ // start is the same
+ // TODO dims is reduced to just cover the offset size
+ if (datasetControllers[controllerIndex]->getName().compare("Binary") == 0) {
+ shared_ptr<XdmfBinaryController> createdController =
+ XdmfBinaryController::New(datasetControllers[controllerIndex]->getFilePath(),
+ datasetControllers[controllerIndex]->getType(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[controllerIndex])->getEndian(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[controllerIndex])->getSeek(),
+ datasetControllers[controllerIndex]->getStart(),
+ datasetControllers[controllerIndex]->getStride(),
+ newDim,
+ datasetControllers[controllerIndex]->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+ else if (datasetControllers[controllerIndex]->getName().compare("HDF") == 0) {
+ // TODO
+ // The writer should only write to contiguous sets when in this mode.
+ // A user would need to do something custom to foul this up.
+ shared_ptr<XdmfHDF5Controller> createdController =
+ XdmfHDF5Controller::New(datasetControllers[controllerIndex]->getFilePath(),
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataSetPath(),
+ datasetControllers[controllerIndex]->getType(),
+ datasetControllers[controllerIndex]->getStart(),
+ datasetControllers[controllerIndex]->getStride(),
+ newDim,
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+ // These are the stats for the first half of the dataset
+ if (sizeRemaining <= datasetControllers[controllerIndex]->getSize() - offset)
+ {
+ // The controller is large enough to need to be split into two controllers
+ std::vector<unsigned int> newStart; //TODO we're assuming one dim for now
+ newStart.push_back(datasetControllers[controllerIndex]->getStart()[0] +sizeRemaining + offset);
+ std::vector<unsigned int> newDim;
+ newDim.push_back(datasetControllers[controllerIndex]->getSize() - (sizeRemaining + offset));
+ // These are the stats of the second controller
+ sizeRemaining = 0;
+ if (datasetControllers[controllerIndex]->getName().compare("Binary") == 0) {
+ shared_ptr<XdmfBinaryController> createdController =
+ XdmfBinaryController::New(datasetControllers[controllerIndex]->getFilePath(),
+ datasetControllers[controllerIndex]->getType(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[controllerIndex])->getEndian(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[controllerIndex])->getSeek(),
+ newStart,
+ datasetControllers[controllerIndex]->getStride(),
+ newDim,
+ datasetControllers[controllerIndex]->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+ else if (datasetControllers[controllerIndex]->getName().compare("HDF") == 0) {
+ // TODO
+ // The writer should only write to contiguous sets when in this mode.
+ // A user would need to do something custom to foul this up.
+ shared_ptr<XdmfHDF5Controller> createdController =
+ XdmfHDF5Controller::New(datasetControllers[controllerIndex]->getFilePath(),
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataSetPath(),
+ datasetControllers[controllerIndex]->getType(),
+ newStart,
+ datasetControllers[controllerIndex]->getStride(),
+ newDim,
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+ }
+ else {
+ // The controller only contains part of the dataset
+ sizeRemaining -= (datasetControllers[controllerIndex]->getSize() - offset);
+ }
+ offset = 0;
+ }
+ else
+ {
+ // in the case of 0 offset, we either need to trim from the front or just use the whole controller
+ if (sizeRemaining > 0)
+ {
+ if (sizeRemaining < datasetControllers[controllerIndex]->getSize())
+ {
+ std::vector<unsigned int> newStart;
+ newStart.push_back(sizeRemaining);
+ std::vector<unsigned int> newDim;
+ newDim.push_back(datasetControllers[controllerIndex]->getSize() - sizeRemaining);
+ sizeRemaining = 0;
+ if (datasetControllers[controllerIndex]->getName().compare("Binary") == 0) {
+ shared_ptr<XdmfBinaryController> createdController =
+ XdmfBinaryController::New(datasetControllers[controllerIndex]->getFilePath(),
+ datasetControllers[controllerIndex]->getType(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[controllerIndex])->getEndian(),
+ shared_dynamic_cast<XdmfBinaryController>(
+ datasetControllers[controllerIndex])->getSeek(),
+ newStart,
+ datasetControllers[controllerIndex]->getStride(),
+ newDim,
+ datasetControllers[controllerIndex]->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+ else if (datasetControllers[controllerIndex]->getName().compare("HDF") == 0) {
+ // TODO
+ // The writer should only write to contiguous sets when in this mode.
+ // A user would need to do something custom to foul this up.
+ shared_ptr<XdmfHDF5Controller> createdController =
+ XdmfHDF5Controller::New(datasetControllers[controllerIndex]->getFilePath(),
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataSetPath(),
+ datasetControllers[controllerIndex]->getType(),
+ newStart,
+ datasetControllers[controllerIndex]->getStride(),
+ newDim,
+ shared_dynamic_cast<XdmfHDF5Controller>(
+ datasetControllers[controllerIndex])->getDataspaceDimensions());
+ returnVector.push_back(createdController);
+ }
+ }
+ else {
+ sizeRemaining -= datasetControllers[controllerIndex]->getSize();
+ }
+ }
+ else
+ {
+ // Just use the current controller
+ returnVector.push_back(datasetControllers[controllerIndex]);
+ }
+ }
+ }
+ }
+ }
+ return returnVector;
+}
+
+class XdmfArrayGatherer : public XdmfVisitor, public Loki::Visitor<XdmfArray>
+{
+ public:
+
+ static shared_ptr<XdmfArrayGatherer>
+ New(std::vector<XdmfArray *> * storageVector)
+ {
+ shared_ptr<XdmfArrayGatherer> p(new XdmfArrayGatherer(storageVector));
+ return p;
+ }
+
+ ~XdmfArrayGatherer()
+ {
+ }
+
+ virtual void
+ visit(XdmfArray & array,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+ {
+ ++mDepth;
+ if (!array.isInitialized())
+ {
+// mStorage->push_back(&array);
+ mArrayCollection.insert(&array);
+ }
+ array.traverse(visitor);
+ --mDepth;
+ if (mDepth == 0)
+ {
+ moveToStorage();
+ }
+ }
+
+ virtual void
+ visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+ {
+ ++mDepth;
+ item.traverse(visitor);
+ --mDepth;
+ if (mDepth == 0)
+ {
+ moveToStorage();
+ }
+ }
+
+ void
+ moveToStorage()
+ {
+ for (std::set<XdmfArray *>::iterator iter = mArrayCollection.begin();
+ iter != mArrayCollection.end();
+ ++iter)
+ {
+ mStorage->push_back(*iter);
+ }
+ }
+
+ private:
+
+ XdmfArrayGatherer(std::vector<XdmfArray *> * storageVector) :
+ mDepth(0),
+ mStorage(storageVector)
+ {
+ }
+
+ unsigned int mDepth;
+ std::set<XdmfArray *> mArrayCollection;
+ std::vector<XdmfArray *> * mStorage;
+};
+
+shared_ptr<XdmfTemplate>
+XdmfTemplate::New()
+{
+ shared_ptr<XdmfTemplate> p(new XdmfTemplate());
+ return p;
+}
+
+
+XdmfTemplate::XdmfTemplate() :
+ mHeavyWriter(shared_ptr<XdmfHeavyDataWriter>()),
+ mBase(shared_ptr<XdmfItem>()),
+ mCurrentStep(-1),
+ mNumSteps(0),
+ mItemFactory(shared_ptr<XdmfItemFactory>())
+{
+}
+
+XdmfTemplate::XdmfTemplate(XdmfTemplate & refTemplate) :
+ XdmfItem(refTemplate),
+ mBase(refTemplate.mBase),
+ mCurrentStep(refTemplate.mCurrentStep),
+ mNumSteps(refTemplate.mNumSteps),
+ mItemFactory(refTemplate.mItemFactory)
+{
+}
+
+XdmfTemplate::~XdmfTemplate()
+{
+}
+
+const std::string XdmfTemplate::ItemTag = "Template";
+
+unsigned int
+XdmfTemplate::addStep()
+{
+ mCurrentStep = this->getNumberSteps();
+ std::stringstream datastream;
+ if (mTrackedArrays.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: XdmfTemplate attempting to add a step when no arrays are tracked");
+ }
+ for (unsigned int arrayIndex = 0; arrayIndex < mTrackedArrays.size(); ++arrayIndex) {
+ if (mTrackedArrayTypes.size() < mTrackedArrays.size()){
+ mTrackedArrayTypes.resize(mTrackedArrays.size());
+ }
+ if (mTrackedArrayDims.size() < mTrackedArrays.size()){
+ mTrackedArrayDims.resize(mTrackedArrays.size());
+ }
+ if (!mTrackedArrayTypes[arrayIndex]) {
+ mTrackedArrayTypes[arrayIndex] = mTrackedArrays[arrayIndex]->getArrayType();
+ }
+ if (mTrackedArrayDims[arrayIndex].size() == 0) {
+ mTrackedArrayDims[arrayIndex] = mTrackedArrays[arrayIndex]->getDimensions();
+ }
+ // Write the tracked arrays to heavy data if they aren't already
+ if (mHeavyWriter) {
+ bool revertToAppend = false;
+ if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Append) {
+ // Set to original heavy data controllers for append
+ if (mDataControllers.size() > arrayIndex)
+ {
+ if (mDataControllers[arrayIndex].size() > 0)
+ {
+ while (mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers() > 0) {
+ mTrackedArrays[arrayIndex]->removeHeavyDataController(0);
+ }
+ for (unsigned int i = 0; i < mDataControllers[arrayIndex].size(); ++i)
+ {
+ mTrackedArrays[arrayIndex]->insert(mDataControllers[arrayIndex][i]);
+ }
+ }
+ }
+ else
+ {
+ // Creating new Dataset
+ // Set to default mode so that it doesn't overlap
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Default);
+ revertToAppend = true;
+ }
+ }
+ else if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Hyperslab) {
+ // Use the controller that references the subset that will be overwritten
+ if (!(arrayIndex < mDataControllers.size()))
+ {
+ // When in overwrite mode the dataset must be preallocated
+ XdmfError::message(XdmfError::FATAL, "Error: Heavy Data dataset must be preallocated "
+ "to use Hyperslab mode Templates");
+ }
+ std::vector<shared_ptr<XdmfHeavyDataController> > overwriteControllers =
+ getStepControllers(mCurrentStep, mTrackedArrayDims[arrayIndex], mDataControllers[arrayIndex]);
+ mTrackedArrays[arrayIndex]->setHeavyDataController(overwriteControllers);
+ }
+ mTrackedArrays[arrayIndex]->accept(mHeavyWriter);
+ if (revertToAppend)
+ {
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Append);
+ }
+ }
+ datastream.str(std::string());
+ for (unsigned int controllerIndex = 0; controllerIndex < mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers(); ++controllerIndex) {
+ // TODO throw error if controller types don't match
+ // For each heavy data controller
+ std::string writerPath = XdmfSystemUtils::getRealPath(mHeavyWriter->getFilePath());
+ std::string heavyDataPath =
+ mTrackedArrays[arrayIndex]->getHeavyDataController(controllerIndex)->getFilePath();
+ size_t index = heavyDataPath.find_last_of("/\\");
+ if(index != std::string::npos) {
+ // If path is not a folder
+ // put the directory path into this variable
+ const std::string heavyDataDir = heavyDataPath.substr(0, index + 1);
+ // If the directory is in the XML File Path
+ if(writerPath.find(heavyDataDir) == 0) {
+ heavyDataPath =
+ heavyDataPath.substr(heavyDataDir.size(),
+ heavyDataPath.size() - heavyDataDir.size());
+ // Pull the file off of the end and place it in the DataPath
+ }
+ // Otherwise the full path is required
+ }
+ datastream << heavyDataPath;
+ datastream << mTrackedArrays[arrayIndex]->getHeavyDataController(controllerIndex)->getDescriptor();
+ datastream << "|";
+ for (unsigned int i = 0; i < mTrackedArrays[arrayIndex]->getHeavyDataController(controllerIndex)->getDimensions().size(); ++i) {
+ datastream << mTrackedArrays[arrayIndex]->getHeavyDataController(controllerIndex)->getDimensions()[i];
+ if (i < mTrackedArrays[arrayIndex]->getHeavyDataController(controllerIndex)->getDimensions().size() - 1) {
+ datastream << " ";
+ }
+ }
+ if (controllerIndex + 1 < mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers()) {
+ datastream << "|";
+ }
+ }
+ if (mHeavyWriter) {
+ if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Append) {
+ if (mDataControllers.size() > arrayIndex)
+ {
+ // If controllers already exist
+ // Store the overarching controllers again
+ mDataControllers[arrayIndex].clear();
+ for (unsigned int i = 0; i < mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers(); ++i)
+ {
+ mDataControllers[arrayIndex].push_back(mTrackedArrays[arrayIndex]->getHeavyDataController(i));
+ }
+ // Clear controllers from the array
+ while (mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers() > 0) {
+ mTrackedArrays[arrayIndex]->removeHeavyDataController(0);
+ }
+ // If append set controller to the correct subsection of the whole
+ std::vector<shared_ptr<XdmfHeavyDataController> > readControllers = getStepControllers(mCurrentStep, mTrackedArrayDims[arrayIndex], mDataControllers[arrayIndex]);
+ mTrackedArrays[arrayIndex]->setHeavyDataController(readControllers);
+ // Replace with updated description
+ mDataDescriptions[arrayIndex] = datastream.str();
+ }
+ else
+ {
+ // If a new dataset, as normal
+ mDataControllers.push_back(std::vector<shared_ptr<XdmfHeavyDataController> >());
+ for (unsigned int i = 0; i < mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers(); ++i) {
+ mDataControllers[mDataControllers.size()-1].push_back((mTrackedArrays[arrayIndex]->getHeavyDataController(i)));
+ }
+ if (mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers() > 0) {
+ mDataTypes.push_back(mTrackedArrays[arrayIndex]->getHeavyDataController(0)->getName());
+ mDataDescriptions.push_back(datastream.str());
+ }
+ }
+ }
+ else if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Hyperslab) {
+ // Hyperslab is already storing the base controller
+ // So nothing is done here, the controller should already be pointing to the correct location
+ // TODO, to what the file index was before the add, as opposed to 0
+ mHeavyWriter->setFileIndex(0);
+ }
+ else {
+ mDataControllers.push_back(std::vector<shared_ptr<XdmfHeavyDataController> >());
+ for (unsigned int i = 0; i < mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers(); ++i) {
+ mDataControllers[mDataControllers.size()-1].push_back((mTrackedArrays[arrayIndex]->getHeavyDataController(i)));
+ }
+ if (mTrackedArrays[arrayIndex]->getNumberHeavyDataControllers() > 0) {
+ mDataTypes.push_back(mTrackedArrays[arrayIndex]->getHeavyDataController(0)->getName());
+ mDataDescriptions.push_back(datastream.str());
+ }
+ }
+ }
+ else {
+ mDataControllers.push_back(std::vector<shared_ptr<XdmfHeavyDataController> >());
+ mDataTypes.push_back("XML");
+ mDataDescriptions.push_back(mTrackedArrays[arrayIndex]->getValuesString());
+ }
+ }
+ ++mNumSteps;
+ this->setIsChanged(true);
+ return mCurrentStep;
+}
+
+void
+XdmfTemplate::clearStep()
+{
+ for (unsigned int i = 0; i < mTrackedArrays.size(); ++i) {
+ mTrackedArrays[i]->release();
+ while (mTrackedArrays[i]->getNumberHeavyDataControllers() > 0) {
+ mTrackedArrays[i]->removeHeavyDataController(0);
+ }
+ }
+ mCurrentStep = -1;
+}
+
+shared_ptr<XdmfItem>
+XdmfTemplate::getBase()
+{
+ return mBase;
+}
+
+shared_ptr<XdmfHeavyDataWriter>
+XdmfTemplate::getHeavyDataWriter()
+{
+ return mHeavyWriter;
+}
+
+std::map<std::string, std::string>
+XdmfTemplate::getItemProperties() const
+{
+ std::map<std::string, std::string> templateProperties;
+/*
+ std::stringstream value;
+ value << mValue;
+ timeProperties.insert(std::make_pair("Value", value.str()));
+*/
+ return templateProperties;
+}
+
+std::string
+XdmfTemplate::getItemTag() const
+{
+ return ItemTag;
+}
+
+unsigned int
+XdmfTemplate::getNumberSteps() const
+{
+ return mNumSteps;
+}
+
+unsigned int
+XdmfTemplate::getNumberTrackedArrays() const
+{
+ return mTrackedArrays.size();
+}
+
+XdmfArray *
+XdmfTemplate::getTrackedArray(unsigned int index)
+{
+ return mTrackedArrays[index];
+}
+
+
+void
+XdmfTemplate::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+
+ // The first child item is the base
+ mBase = childItems[0];
+ mCurrentStep = 0;
+
+ std::string referenceHDF5File = "";
+
+ if (childItems.size() > 1) {
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin() + 1;
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ // Pull hdf5 reference data from the first provided array
+ if (array->getNumberHeavyDataControllers() > 0 & !mHeavyWriter) {
+ mHeavyWriter = reader->generateHeavyDataWriter(array->getHeavyDataController(0)->getName(), array->getHeavyDataController(0)->getFilePath());
+ }
+ if (array->getName().compare("Data Description") == 0) {
+ // Split description into substrings based on the " character
+ array->read();
+
+ std::string descriptionString;
+ if (array->getArrayType() == XdmfArrayType::Int8())
+ {
+ descriptionString = std::string((char *)array->getValuesInternal());
+ }
+ else if (array->getArrayType() == XdmfArrayType::String())
+ {
+ std::stringstream descriptionstream;
+ for (unsigned int i = 0; i < array->getSize(); ++i)
+ {
+ descriptionstream << array->getValue<std::string>(i);
+ if (i < array->getSize() - 1)
+ {
+ descriptionstream << '|';
+ }
+ }
+ descriptionString = descriptionstream.str();
+ }
+
+ size_t index = descriptionString.find_first_of("\"");
+ size_t previousIndex = 0;
+
+ if (index != std::string::npos) {
+ // Removing the prepended "
+ previousIndex = index + 1;
+ index = descriptionString.find_first_of("\"", previousIndex);
+ }
+
+ while (index != std::string::npos) {
+ std::string type = descriptionString.substr(previousIndex, index - previousIndex);
+ mDataTypes.push_back(type);
+ previousIndex = index + 1;
+ index = descriptionString.find_first_of("\"", previousIndex);
+ if (index - previousIndex > 0) {
+ std::string description;
+ description = descriptionString.substr(previousIndex, index - previousIndex);
+ mDataDescriptions.push_back(description);
+ // create controllers here based on the type/description?
+ // Is array type already filled?
+ // Potentially call "fillControllers" after populating?
+ if (index != std::string::npos) {
+ previousIndex = index + 1;
+ index = descriptionString.find_first_of("\"", previousIndex);
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Type without a description in XdmfTemplate::populateItem");
+ }
+ }
+ }
+ else {
+ mTrackedArrays.push_back(array.get());
+ mTrackedArrayDims.push_back(array->getDimensions());
+ mTrackedArrayTypes.push_back(array->getArrayType());
+ }
+ }
+ }
+ }
+ for (unsigned int i = 0; i < mDataTypes.size(); ++i)
+ {
+ mDataControllers.push_back(std::vector<shared_ptr<XdmfHeavyDataController> >());
+ }
+ mDataControllers.resize(mDataTypes.size());
+ if (!mItemFactory) {
+ mItemFactory = XdmfItemFactory::New();
+ }
+ std::map<std::string, std::string> populateProperties;
+ if (mHeavyWriter) {
+ // The heavy writer provides the XMLDir, which is used to get full paths for the controllers
+ // It is assumed that the files that the controllers reference are in the same directory
+ // as the file that the writer references
+ std::string filepath = XdmfSystemUtils::getRealPath(mHeavyWriter->getFilePath());
+ size_t index = filepath.find_last_of("/\\");
+ filepath = filepath.substr(0, index + 1);
+ populateProperties["XMLDir"] = filepath;
+ }
+ else
+ {
+ // Error because a writer is required? TODO
+ }
+ for (unsigned int i = 0; i < mDataDescriptions.size(); ++i) {
+ populateProperties["Content"] = mDataDescriptions[i];
+ std::vector<shared_ptr<XdmfHeavyDataController> > readControllers =
+ reader->generateHeavyDataControllers(populateProperties, mTrackedArrayDims[i % mTrackedArrays.size()], mTrackedArrayTypes[i % mTrackedArrays.size()], mDataTypes[i]);
+ if (readControllers.size() > 0) {
+ // Heavy data controllers reference the data
+ for (unsigned int j = 0; j < readControllers.size(); ++j) {
+ mDataControllers[i].push_back(readControllers[j]);
+ }
+ }
+ }
+ // Compare the first set of controllers to the size of the first array
+ unsigned int controllerTotal = 0;
+
+ for (unsigned int i = 0; i < mDataControllers[0].size(); ++i)
+ {
+ unsigned int previousTotal = controllerTotal;
+ controllerTotal += mDataControllers[0][i]->getSize();
+ if (previousTotal != controllerTotal - mDataControllers[0][i]->getSize())
+ {
+ controllerTotal = UINT_MAX;
+ break;
+ }
+ }
+ // If the array is smaller, set the writer to append.
+ if (controllerTotal > mTrackedArrays[0]->getSize())
+ {
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Append);
+ mNumSteps = 0;
+ unsigned int currentTotal = 0;
+ for (unsigned int controllerIndex = 0; controllerIndex < mDataControllers[0].size(); ++controllerIndex)
+ {
+ currentTotal += mDataControllers[0][controllerIndex]->getSize();
+ while (currentTotal >= mTrackedArrays[0]->getSize())
+ {
+ currentTotal -= mTrackedArrays[0]->getSize();
+ ++mNumSteps;
+ }
+ }
+// mNumSteps = controllerTotal / mTrackedArrays[0]->getSize();
+ }
+ else {
+ mNumSteps = mDataControllers.size() / mTrackedArrays.size();
+ }
+ this->setStep(0);
+}
+
+void
+XdmfTemplate::preallocateSteps(unsigned int numSteps)
+{
+ // Preallocate steps based on the current size of the arrays
+ // Use a temporary array to write data to hdf5
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ // Set to Default mode so that the new allocations are in new locations
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Default);
+ int preallocatedSize = 0;
+ int numberSetsPreallocated = 0;
+ std::stringstream datastream;
+ for (unsigned int i = 0; i < mTrackedArrays.size(); ++i) {
+ preallocatedSize = mTrackedArrays[i]->getSize() * numSteps;
+///*
+ numberSetsPreallocated = 1;
+
+ int adjustment = 1;
+ while (preallocatedSize / (numSteps/adjustment) != mTrackedArrays[i]->getSize() || 0 > (int)preallocatedSize) {
+// XdmfError::message(XdmfError::WARNING, "Overflow error");
+ ++adjustment;
+ while (numSteps % adjustment != 0) {
+//printf("%d / %d remainder %d\n", numSteps, adjustment, (numSteps % adjustment));
+ ++adjustment;
+ }
+ numberSetsPreallocated = numberSetsPreallocated * adjustment;
+ preallocatedSize = mTrackedArrays[i]->getSize() * (numSteps / adjustment);
+//printf("%d / %d = %d ?= %d\n", preallocatedSize , (numSteps/adjustment), preallocatedSize / (numSteps/adjustment), mTrackedArrays[i]->getSize());
+ }
+
+ // If adjusted, split one more time, to ensure that the dataset fits.
+ if (adjustment > 1) {
+ ++adjustment;
+ while (numSteps % adjustment != 0) {
+ ++adjustment;
+ }
+ numberSetsPreallocated = numberSetsPreallocated * adjustment;
+ preallocatedSize = mTrackedArrays[i]->getSize() * (numSteps / adjustment);
+ }
+
+ bool allocateSucceeded = false;
+ while (!allocateSucceeded)
+ {
+ try {
+ mHeavyWriter->openFile();
+//printf("now size %d allocated %d times\n", preallocatedSize, numberSetsPreallocated);
+ for (unsigned int allocateIteration = 0;
+ allocateIteration < numberSetsPreallocated;
+ ++allocateIteration)
+ {
+//printf("allocating subsection %u\n", allocateIteration);
+//*/
+//printf("initializing base array\n");
+ tempArray->initialize(mTrackedArrays[i]->getArrayType(), preallocatedSize);
+//printf("writing subsection");
+ tempArray->accept(mHeavyWriter);
+//printf("subsection written\n");
+// mHeavyWriter->clearCache();
+///*
+ if (mDataControllers.size() <= i) {
+ mDataControllers.push_back(std::vector<shared_ptr<XdmfHeavyDataController> >());
+ }
+ // Clean Array for the next iteration
+ while (tempArray->getNumberHeavyDataControllers() > 0) {
+ mDataControllers[i].push_back(tempArray->getHeavyDataController(0));
+ if (mDataTypes.size() <= i) {
+ mDataTypes.push_back(tempArray->getHeavyDataController(0)->getName());
+ }
+ tempArray->removeHeavyDataController(0);
+ }
+ tempArray->release();
+//*/
+///*
+//printf("moving to next allocation\n");
+ }
+ mHeavyWriter->closeFile();
+ allocateSucceeded = true;
+//*/
+//TODO catch the controllers created by this.
+///*
+ }
+ catch (...)
+ {
+ while (tempArray->getNumberHeavyDataControllers() > 0) {
+ tempArray->removeHeavyDataController(0);
+ }
+ tempArray->release();
+// XdmfError::message(XdmfError::WARNING, "Array Allocation failed");
+ int factor = 2;
+ while (preallocatedSize % factor != 0) {
+//printf("%d / %d remainder %d\n", preallocatedSize, factor, (preallocatedSize % factor));
+ factor = factor + 1;
+ }
+//printf("adjusted factor %d\n", factor);
+ numberSetsPreallocated = numberSetsPreallocated * factor;
+ preallocatedSize = (preallocatedSize) / factor;
+//printf("now size %d allocated %d times\n", preallocatedSize, numberSetsPreallocated);
+ }
+ }
+//printf("Done writing to hdf5\n");
+//*/
+/*
+ // Transfer controllers to the appropriate slot before clearing them
+ if (mDataControllers.size() <= i) {
+ mDataControllers.push_back(std::vector<shared_ptr<XdmfHeavyDataController> >());
+ }
+ // Clean Array for the next iteration
+ while (tempArray->getNumberHeavyDataControllers() > 0) {
+ mDataControllers[i].push_back(tempArray->getHeavyDataController(0));
+ if (mDataTypes.size() <= i) {
+ mDataTypes.push_back(tempArray->getHeavyDataController(0)->getName());
+ }
+ tempArray->removeHeavyDataController(0);
+ }
+ tempArray->release();
+*/
+ datastream.str(std::string());
+ for (unsigned int controllerIndex = 0; controllerIndex < mDataControllers[i].size(); ++controllerIndex) {
+ // TODO throw error if controller types don't match
+ // For each heavy data controller
+ std::string writerPath = XdmfSystemUtils::getRealPath(mHeavyWriter->getFilePath());
+ std::string heavyDataPath =
+ mDataControllers[i][controllerIndex]->getFilePath();
+ size_t index = heavyDataPath.find_last_of("/\\");
+ if(index != std::string::npos) {
+ // If path is not a folder
+ // put the directory path into this variable
+ const std::string heavyDataDir = heavyDataPath.substr(0, index + 1);
+ // If the directory is in the XML File Path
+ if(writerPath.find(heavyDataDir) == 0) {
+ heavyDataPath =
+ heavyDataPath.substr(heavyDataDir.size(),
+ heavyDataPath.size() - heavyDataDir.size());
+ // Pull the file off of the end and place it in the DataPath
+ }
+ // Otherwise the full path is required
+ }
+ datastream << heavyDataPath;
+ datastream << mDataControllers[i][controllerIndex]->getDescriptor();
+ datastream << "|";
+ for (unsigned int j = 0; j < mDataControllers[i][controllerIndex]->getDimensions().size(); ++j) {
+ datastream << mDataControllers[i][controllerIndex]->getDimensions()[j];
+ if (j < mDataControllers[i][controllerIndex]->getDimensions().size() - 1) {
+ datastream << " ";
+ }
+ }
+ if (controllerIndex + 1 < mDataControllers[i].size()) {
+ datastream << "|";
+ }
+ }
+ mDataDescriptions.push_back(datastream.str());
+ }
+ // To end set the heavy writer to overwrite mode
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Hyperslab);
+}
+
+
+void
+XdmfTemplate::removeStep(unsigned int stepId)
+{
+ if (stepId < this->getNumberSteps()) {
+ for (unsigned int i = 0; i < mTrackedArrays.size(); ++i) {
+ if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Append ||
+ mHeavyWriter->getMode() == XdmfHeavyDataWriter::Hyperslab) {
+ std::vector<shared_ptr<XdmfHeavyDataController> > replacementControllers = getControllersExcludingStep(stepId, mTrackedArrayDims[i], mDataControllers[i]);
+ for (unsigned int j = 0; j < replacementControllers.size(); ++j)
+ {
+ if (mDataControllers[i].size() > j) {
+ mDataControllers[i][j] = replacementControllers[j];
+ }
+ else {
+ mDataControllers[i].push_back(replacementControllers[j]);
+ }
+ }
+ }
+ else {
+ mDataTypes.erase(mDataTypes.begin() + (stepId*mTrackedArrays.size()));
+ mDataDescriptions.erase(mDataDescriptions.begin() + (stepId*mTrackedArrays.size()));
+ mDataControllers.erase(mDataControllers.begin() + (stepId*mTrackedArrays.size()));
+ }
+ }
+ --mNumSteps;
+ }
+ mCurrentStep = -1;
+ this->setIsChanged(true);
+}
+
+void
+XdmfTemplate::setBase(shared_ptr<XdmfItem> newBase)
+{
+ shared_ptr<XdmfArrayGatherer> accumulator = XdmfArrayGatherer::New(&mTrackedArrays);
+ newBase->accept(accumulator);
+ mBase = newBase;
+ this->setIsChanged(true);
+}
+
+void
+XdmfTemplate::setHeavyDataWriter(shared_ptr<XdmfHeavyDataWriter> writer)
+{
+ mHeavyWriter = writer;
+}
+
+void
+XdmfTemplate::setStep(unsigned int stepId)
+{
+ if (stepId != mCurrentStep) {
+ if (!mItemFactory) {
+ mItemFactory = XdmfItemFactory::New();
+ }
+ if (stepId < this->getNumberSteps()) {
+ for (unsigned int i = 0; i < mTrackedArrays.size(); ++i) {
+ unsigned int arrayIndex = 0;
+ if (mHeavyWriter) {
+ if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Append ||
+ mHeavyWriter->getMode() == XdmfHeavyDataWriter::Hyperslab) {
+ arrayIndex = i;
+ }
+ else {
+ arrayIndex = i+(stepId*mTrackedArrays.size());
+ }
+ }
+ else {
+ arrayIndex = i+(stepId*mTrackedArrays.size());
+ }
+ if (mDataControllers[arrayIndex].size() > 0) {
+ if(mHeavyWriter) {
+ if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Append ||
+ mHeavyWriter->getMode() == XdmfHeavyDataWriter::Hyperslab) {
+ std::vector<shared_ptr<XdmfHeavyDataController> > insertVector =
+ getStepControllers(stepId, mTrackedArrayDims[i], mDataControllers[i]);
+ mTrackedArrays[i]->setHeavyDataController(insertVector);
+ }
+ else {
+ mTrackedArrays[i]->setHeavyDataController(mDataControllers[i+(stepId*mTrackedArrays.size())]);
+ }
+ }
+ else {
+ mTrackedArrays[i]->setHeavyDataController(mDataControllers[i+(stepId*mTrackedArrays.size())]);
+ }
+ }
+ else {
+ std::map<std::string, std::string> populateProperties;
+ if (mHeavyWriter) {
+ // The heavy writer provides the XMLDir, which is used to get full paths for the controllers
+ // It is assumed that the files that the controllers reference are in the same directory
+ // as the file that the writer references
+ std::string filepath = XdmfSystemUtils::getRealPath(mHeavyWriter->getFilePath());
+ size_t index = filepath.find_last_of("/\\");
+ filepath = filepath.substr(0, index + 1);
+ populateProperties["XMLDir"] = filepath;
+ }
+ populateProperties["Content"] = mDataDescriptions[arrayIndex];
+ std::vector<shared_ptr<XdmfHeavyDataController> > readControllers;
+ if (mHeavyWriter) {
+ if (mHeavyWriter->getMode() == XdmfHeavyDataWriter::Append ||
+ mHeavyWriter->getMode() == XdmfHeavyDataWriter::Hyperslab) {
+ std::vector<shared_ptr<XdmfHeavyDataController> > totalControllers =
+ mItemFactory->generateHeavyDataControllers(populateProperties, mTrackedArrayDims[i], mTrackedArrayTypes[i], mDataTypes[i+(stepId*mTrackedArrays.size())]);
+ readControllers = getStepControllers(stepId, mTrackedArrayDims[i], totalControllers);
+ }
+ else {
+ readControllers = mItemFactory->generateHeavyDataControllers(populateProperties, mTrackedArrayDims[i], mTrackedArrayTypes[i], mDataTypes[i+(stepId*mTrackedArrays.size())]);
+ }
+ }
+ else {
+ readControllers = mItemFactory->generateHeavyDataControllers(populateProperties, mTrackedArrayDims[i], mTrackedArrayTypes[i], mDataTypes[i+(stepId*mTrackedArrays.size())]);
+ }
+ if (readControllers.size() > 0) {
+ // Heavy data controllers reference the data
+ mTrackedArrays[i]->setHeavyDataController(readControllers);
+ mDataControllers[arrayIndex] = readControllers;
+ }
+ else {
+ // Data is contained in the content
+ std::string content = mDataDescriptions[i+(stepId*mTrackedArrays.size())];
+
+ mTrackedArrays[i]->initialize(mTrackedArrayTypes[i], mTrackedArrayDims[i]);
+
+ unsigned int index = 0;
+ boost::char_separator<char> sep(" \t\n");
+ boost::tokenizer<boost::char_separator<char> > valtokens(content, sep);
+ if(mTrackedArrayTypes[i] == XdmfArrayType::String()) {
+ for(boost::tokenizer<boost::char_separator<char> >::const_iterator
+ iter = valtokens.begin();
+ iter != valtokens.end();
+ ++iter, ++index) {
+ mTrackedArrays[i]->insert(index, *iter);
+ }
+ }
+ else {
+ for(boost::tokenizer<boost::char_separator<char> >::const_iterator
+ iter = valtokens.begin();
+ iter != valtokens.end();
+ ++iter, ++index) {
+ mTrackedArrays[i]->insert(index, atof((*iter).c_str()));
+ }
+ }
+ }
+ }
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Template attempting to load invalid step");
+ }
+ mCurrentStep = stepId;
+ }
+}
+
+void
+XdmfTemplate::trackArray(shared_ptr<XdmfArray> newArray)
+{
+ bool found = false;
+
+ for (unsigned int i = 0; i < mTrackedArrays.size() && !found; ++i) {
+ if (mTrackedArrays[i] == newArray.get()) {
+ found = true;
+ }
+ }
+
+ if (!found) {
+ mTrackedArrays.push_back(newArray.get());
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfTemplate::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ // Set to the first step when writing, as the first step is the model for the rest of the template
+ // Will fail if there are no steps
+ if (this->getNumberSteps() == 0) {
+ XdmfError::message(XdmfError::FATAL, "Error: No steps in template in XdmfTemplate::traverse");
+ }
+ this->clearStep();
+
+ unsigned int arraysize = 1;
+ for (unsigned int i = 0; i < mTrackedArrayDims[0].size(); ++i)
+ {
+ arraysize *= mTrackedArrayDims[0][i];
+ }
+
+ unsigned int controllersize = 0;
+ for (unsigned int i = 0; i < mDataControllers[0].size(); ++i)
+ {
+ controllersize += mDataControllers[0][i]->getSize();
+ }
+
+ XdmfHeavyDataWriter::Mode originalMode;
+
+ if (mHeavyWriter)
+ {
+ originalMode = mHeavyWriter->getMode();
+ if (controllersize > arraysize) {
+ mHeavyWriter->setMode(XdmfHeavyDataWriter::Append);
+ }
+ }
+
+ this->setStep(0);
+
+ if (mHeavyWriter)
+ {
+ mHeavyWriter->setMode(originalMode);
+ }
+
+ // Sending visitor to the base first so that it appears first when reading.
+ mBase->accept(visitor);
+
+ for (unsigned int i = 0; i < mTrackedArrays.size(); ++i) {
+ mTrackedArrays[i]->release();
+ mTrackedArrays[i]->accept(visitor);
+ }
+
+ // Create an array to hold all of the data information strings
+
+ bool originalXPath;
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ originalXPath = writer->getWriteXPaths();
+ writer->setWriteXPaths(false);
+ }
+
+ shared_ptr<XdmfArray> dataInfoArray = XdmfArray::New();
+
+ dataInfoArray->setName("Data Description");
+
+ unsigned int i = 0;
+
+ std::stringstream arrayInfo;
+ while (i < mDataTypes.size()) {
+ arrayInfo << "\"" << mDataTypes[i] << "\"" << mDataDescriptions[i];
+ ++i;
+ }
+ dataInfoArray->insert(0, arrayInfo.str().c_str(), arrayInfo.str().length());
+ dataInfoArray->insert(dataInfoArray->getSize(), 0);
+
+ dataInfoArray->accept(visitor);
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ writer->setWriteXPaths(originalXPath);
+ }
+
+ XdmfItem::traverse(visitor);
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfTemplate, XDMFTEMPLATE)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTemplate.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFTEMPLATE_HPP_
+#define XDMFTEMPLATE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfItemFactory.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+
+/**
+ * @brief Defines a template that can be filled with multiple sets of data.
+ *
+ * An XdmfTemplate defines a structure. The arrays within that structure
+ * are stored if they are not initialized when the structure is first set.
+ * Steps can then be added and references to heavy data are produced and
+ * stored for later retrieval.
+ *
+ * This effectively lets an object have several variations with different
+ * contained data.
+ */
+class XDMF_EXPORT XdmfTemplate : public virtual XdmfItem {
+
+public:
+
+ /**
+ * Creates a new instance of the XdmfTemplate object
+ *
+ * @return A constructed XdmfTemplate object.
+ */
+ static shared_ptr<XdmfTemplate> New();
+
+ virtual ~XdmfTemplate();
+
+ LOKI_DEFINE_VISITABLE(XdmfTemplate, XdmfItem);
+ static const std::string ItemTag;
+
+ /**
+ * Writes all tracked arrays to heavy data via the provided
+ * heavy data writer then stores the heavy data descriptions.
+ *
+ * @return The ID of the step that was added
+ */
+ virtual unsigned int addStep();
+
+ /**
+ * Clears the current data from the tracked arrays.
+ */
+ virtual void clearStep();
+
+ /**
+ * Gets the XdmfItem that serves as the structure for the template.
+ *
+ * @return The XdmfItem that serves as the structure for the template.
+ */
+ virtual shared_ptr<XdmfItem> getBase();
+
+ /**
+ * Gets the heavy data writer that is used to write step data to heavy data.
+ *
+ * @return The heavy data writer
+ */
+ shared_ptr<XdmfHeavyDataWriter> getHeavyDataWriter();
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Gets the number of steps currently contained within the template.
+ *
+ * @return The number of steps contained within the template.
+ */
+ unsigned int getNumberSteps() const;
+
+ /**
+ * Gets the number of arrays tracked across timesteps.
+ *
+ * @return The numer of tracked arrays.
+ */
+ unsigned int getNumberTrackedArrays() const;
+
+ /**
+ * Gets the tracked array at the specified index. The index of the array
+ * depends on when the internal visitor encountered the array in question.
+ *
+ * @return The requested array.
+ */
+ XdmfArray * getTrackedArray(unsigned int index);
+
+ using XdmfItem::insert;
+
+ /*
+ *
+ */
+ virtual void preallocateSteps(unsigned int numSteps);
+
+ /**
+ *
+ */
+ virtual void removeStep(unsigned int stepId);
+
+ /**
+ * Sets the item to define the structure for each step of the template.
+ *
+ * When the base is set all uninitialized arrays are added to
+ * the list of tracked arrays.
+ *
+ * @param newBase The item to serve as the structure.
+ */
+ virtual void setBase(shared_ptr<XdmfItem> newBase);
+
+ /**
+ * Sets the heavy data writer with which the template will write
+ * to heavy data when adding a step.
+ *
+ * @param writer The writer to be used to write to heavy data.
+ */
+ void setHeavyDataWriter(shared_ptr<XdmfHeavyDataWriter> writer);
+
+ /**
+ * Reads in the heavy data associated with the provided step id.
+ *
+ * @param stepId The id of the step whose heavy data
+ * is to be read in from file
+ */
+ virtual void setStep(unsigned int stepId);
+
+ /**
+ * Adds an array to the list of tracked arrays if that array
+ * is not already there.
+ *
+ * The setBase method automatically sets uninitialized arrays
+ * to be tracked, this can be used to add any missed by setBase.
+ *
+ * @param newArray The array to be tracked.
+ */
+ virtual void trackArray(shared_ptr<XdmfArray> newArray);
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfTemplate(XdmfTemplate &);
+
+protected:
+
+ XdmfTemplate();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+ shared_ptr<XdmfHeavyDataWriter> mHeavyWriter;
+
+ shared_ptr<XdmfItem> mBase;
+ std::vector<XdmfArray *> mTrackedArrays;
+ std::vector<std::string> mDataTypes;
+ std::vector<std::string> mDataDescriptions;
+ std::vector<std::vector<shared_ptr<XdmfHeavyDataController> > > mDataControllers;
+ std::vector<shared_ptr<const XdmfArrayType> > mTrackedArrayTypes;
+ std::vector<std::vector<unsigned int> > mTrackedArrayDims;
+ int mCurrentStep;
+ unsigned int mNumSteps;
+ shared_ptr<XdmfItemFactory> mItemFactory;
+
+private:
+
+ XdmfTemplate(const XdmfTemplate &); // Not implemented.
+ void operator=(const XdmfTemplate &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFTEMPLATE; // Simply as a typedef to ensure correct typing
+typedef struct XDMFTEMPLATE XDMFTEMPLATE;
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfTemplate, XDMFTEMPLATE, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* XDMFTEMPLATE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTime.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <sstream>
+#include <utility>
+#include "XdmfTime.hpp"
+#include "XdmfError.hpp"
+
+shared_ptr<XdmfTime>
+XdmfTime::New(const double & value)
+{
+ shared_ptr<XdmfTime> p(new XdmfTime(value));
+ return p;
+}
+
+XdmfTime::XdmfTime(const double & value) :
+ mValue(value)
+{
+}
+
+XdmfTime::XdmfTime(XdmfTime & refTime) :
+ XdmfItem(refTime),
+ mValue(refTime.getValue())
+{
+}
+
+XdmfTime::~XdmfTime()
+{
+}
+
+const std::string XdmfTime::ItemTag = "Time";
+
+std::map<std::string, std::string>
+XdmfTime::getItemProperties() const
+{
+ std::map<std::string, std::string> timeProperties;
+ std::stringstream value;
+ value << mValue;
+ timeProperties.insert(std::make_pair("Value", value.str()));
+ return timeProperties;
+}
+
+std::string
+XdmfTime::getItemTag() const
+{
+ return ItemTag;
+}
+
+double
+XdmfTime::getValue() const
+{
+ return mValue;
+}
+
+void
+XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ std::map<std::string, std::string>::const_iterator value =
+ itemProperties.find("Value");
+ if(value != itemProperties.end()) {
+ mValue = atof(value->second.c_str());
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'Value' not in itemProperties in "
+ "XdmfTime::populateItem");
+ }
+}
+
+void
+XdmfTime::setValue(const double & value)
+{
+ mValue = value;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+XDMFTIME * XdmfTimeNew(double value)
+{
+ try
+ {
+ return (XDMFTIME *)((void *)(new XdmfTime(*(XdmfTime::New(value).get()))));
+ }
+ catch (...)
+ {
+ return (XDMFTIME *)((void *)(new XdmfTime(*(XdmfTime::New(value).get()))));
+ }
+}
+
+double XdmfTimeGetValue(XDMFTIME * timePointer)
+{
+ return ((XdmfTime *)timePointer)->getValue();
+}
+
+void XdmfTimeSetValue(XDMFTIME * timePointer, double time)
+{
+ ((XdmfTime *)timePointer)->setValue(time);
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfTime, XDMFTIME)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTime.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFTIME_HPP_
+#define XDMFTIME_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfItem.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Time specification for an XdmfGrid.
+ *
+ * An XdmfTime sets a time value for an XdmfGrid.
+ */
+class XDMF_EXPORT XdmfTime : public XdmfItem {
+
+public:
+
+ /**
+ * Create a new XdmfTime.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTime.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTime.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param value The timeValue of the XdmfTime to create.
+ * @return The new XdmfTime.
+ */
+ static shared_ptr<XdmfTime> New(const double & value = 0);
+
+ virtual ~XdmfTime();
+
+ LOKI_DEFINE_VISITABLE(XdmfTime, XdmfItem)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the time value associated with this XdmfTime.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTime.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getValue
+ * @until //#getValue
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTime.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getValue
+ * @until #//getValue
+ *
+ * @return A double containing the time value.
+ */
+ double getValue() const;
+
+ /**
+ * Set the time value associated with this XdmfTime.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTime.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setValue
+ * @until //#setValue
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTime.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setValue
+ * @until #//setValue
+ *
+ * @param time A double containing the time value.
+ */
+ void setValue(const double & time);
+
+ XdmfTime(XdmfTime &);
+
+protected:
+
+ XdmfTime(const double & value);
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfTime(const XdmfTime &); // Not implemented.
+ void operator=(const XdmfTime &); // Not implemented.
+
+ double mValue;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFTIME; // Simply as a typedef to ensure correct typing
+typedef struct XDMFTIME XDMFTIME;
+
+XDMF_EXPORT XDMFTIME * XdmfTimeNew(double value);
+
+XDMF_EXPORT double XdmfTimeGetValue(XDMFTIME * timePointer);
+
+XDMF_EXPORT void XdmfTimeSetValue(XDMFTIME * timePointer, double time);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfTime, XDMFTIME, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFTIME_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTopology.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <sstream>
+#include <utility>
+#include "XdmfError.hpp"
+#include "XdmfFunction.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfTopologyType.hpp"
+
+shared_ptr<XdmfTopology>
+XdmfTopology::New()
+{
+ shared_ptr<XdmfTopology> p(new XdmfTopology());
+ return p;
+}
+
+XdmfTopology::XdmfTopology() :
+ mType(XdmfTopologyType::NoTopologyType()),
+ mBaseOffset(0)
+{
+}
+
+XdmfTopology::XdmfTopology(XdmfTopology & refTopo) :
+ XdmfArray(refTopo),
+ mType(refTopo.mType)
+{
+}
+
+XdmfTopology::~XdmfTopology()
+{
+}
+
+const std::string XdmfTopology::ItemTag = "Topology";
+
+int
+XdmfTopology::getBaseOffset() const
+{
+ return mBaseOffset;
+}
+
+std::string
+XdmfTopology::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::map<std::string, std::string>
+XdmfTopology::getItemProperties() const
+{
+ std::map<std::string, std::string> topologyProperties;
+ mType->getProperties(topologyProperties);
+ if(mType->getCellType() != XdmfTopologyType::Structured) {
+ std::stringstream numElements;
+ numElements << this->getNumberElements();
+ topologyProperties.insert(std::make_pair("Dimensions", numElements.str()));
+ }
+ if (mBaseOffset != 0)
+ {
+ std::stringstream offsetString;
+ offsetString << mBaseOffset;
+ topologyProperties.insert(std::make_pair("BaseOffset", offsetString.str()));
+ }
+ return topologyProperties;
+}
+
+unsigned int
+XdmfTopology::getNumberElements() const
+{
+ // deal with special cases first (mixed / no topology)
+ if(mType->getNodesPerElement() == 0) {
+ if(mType == XdmfTopologyType::Mixed()) {
+ unsigned int index = 0;
+ unsigned int numberElements = 0;
+ // iterate over all values in connectivity, pulling topology type ids
+ // and counting number of elements
+ while(index < this->getSize()) {
+ const unsigned int id = this->getValue<unsigned int>(index);
+ const shared_ptr<const XdmfTopologyType> topologyType =
+ XdmfTopologyType::New(id);
+ if(topologyType == NULL) {
+ XdmfError::message(XdmfError::FATAL,
+ "Invalid topology type id found in connectivity "
+ "when parsing mixed topology.");
+ }
+ if(topologyType == XdmfTopologyType::Polyvertex()) {
+ const unsigned int numberPolyvertexElements =
+ this->getValue<unsigned int>(index + 1);
+ numberElements += numberPolyvertexElements;
+ index += numberPolyvertexElements + 2;
+ }
+ else if(topologyType == XdmfTopologyType::Polyline(0) ||
+ topologyType == XdmfTopologyType::Polygon(0)) {
+ const unsigned int numberNodes =
+ this->getValue<unsigned int>(index + 1);
+ numberElements += 1;
+ index += numberNodes + 2;
+ }
+ else if(topologyType == XdmfTopologyType::Polyhedron()) {
+ // get number of face
+ const unsigned int numberFaces =
+ this->getValue<unsigned int>(index + 1);
+ // skip to first face
+ index += 2;
+ // iterate over all faces and add number of nodes per face to index
+ for(unsigned int i=0; i<numberFaces; ++i) {
+ index += this->getValue<unsigned int>(index) + 1;
+ }
+ numberElements += 1;
+ }
+ else {
+ // add 1 to element count and move to next element id
+ numberElements += 1;
+ index += topologyType->getNodesPerElement() + 1;
+ }
+ }
+ return numberElements;
+ }
+ return 0;
+ }
+ return this->getSize() / mType->getNodesPerElement();
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopology::getType() const
+{
+ return mType;
+}
+
+void
+XdmfTopology::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ mType = XdmfTopologyType::New(itemProperties);
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ this->swap(array);
+ if (array->getReference()) {
+ this->setReference(array->getReference());
+ this->setReadMode(XdmfArray::Reference);
+ }
+ break;
+ }
+ }
+
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Offset");
+ if (type != itemProperties.end()) {
+ type = itemProperties.find("BaseOffset");
+ }
+ if (type != itemProperties.end()) {
+ // Convert to double
+ double offset = atof(type->second.c_str());
+ std::stringstream expressionStream;
+ expressionStream << offset << "+X";
+ std::map<std::string, shared_ptr<XdmfArray> > offsetMap;
+ shared_ptr<XdmfArray> offsetBase = XdmfArray::New();
+ this->swap(offsetBase);
+ offsetMap["X"] = offsetBase;
+ shared_ptr<XdmfFunction> offsetFunction = XdmfFunction::New(expressionStream.str(), offsetMap);
+ this->setReference(offsetFunction);
+ this->setReadMode(XdmfArray::Reference);
+ }
+}
+
+void
+XdmfTopology::setBaseOffset(int offset)
+{
+ mBaseOffset = offset;
+}
+
+void
+XdmfTopology::setType(const shared_ptr<const XdmfTopologyType> type)
+{
+ mType = type;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+XDMFTOPOLOGY * XdmfTopologyNew()
+{
+ try
+ {
+ shared_ptr<XdmfTopology> generatedTopology = XdmfTopology::New();
+ return (XDMFTOPOLOGY *)((void *)(new XdmfTopology(*generatedTopology.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfTopology> generatedTopology = XdmfTopology::New();
+ return (XDMFTOPOLOGY *)((void *)(new XdmfTopology(*generatedTopology.get())));
+ }
+}
+
+unsigned int XdmfTopologyGetNumberElements(XDMFTOPOLOGY * topology, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return ((XdmfTopology *)topology)->getNumberElements();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+int XdmfTopologyGetType(XDMFTOPOLOGY * topology)
+{
+ shared_ptr<const XdmfTopologyType> type = ((XdmfTopology *)topology)->getType();
+ int returnType = -1;
+
+ if (type->getID() == XdmfTopologyType::Polyvertex()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_POLYVERTEX;
+ }
+ else if (type->getID() == XdmfTopologyType::Polyline(0)->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_POLYLINE;
+ }
+ else if (type->getID() == XdmfTopologyType::Polygon(0)->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_POLYGON;
+ }
+ else if (type->getID() == XdmfTopologyType::Triangle()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_TRIANGLE;
+ }
+ else if (type->getID() == XdmfTopologyType::Quadrilateral()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_QUADRILATERAL;
+ }
+ else if (type->getID() == XdmfTopologyType::Tetrahedron()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_TETRAHEDRON;
+ }
+ else if (type->getID() == XdmfTopologyType::Pyramid()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_PYRAMID;
+ }
+ else if (type->getID() == XdmfTopologyType::Wedge()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_WEDGE;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON;
+ }
+ else if (type->getID() == XdmfTopologyType::Edge_3()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_EDGE_3;
+ }
+ else if (type->getID() == XdmfTopologyType::Triangle_6()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_TRIANGLE_6;
+ }
+ else if (type->getID() == XdmfTopologyType::Quadrilateral_8()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8;
+ }
+ else if (type->getID() == XdmfTopologyType::Quadrilateral_9()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9;
+ }
+ else if (type->getID() == XdmfTopologyType::Tetrahedron_10()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10;
+ }
+ else if (type->getID() == XdmfTopologyType::Pyramid_13()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_PYRAMID_13;
+ }
+ else if (type->getID() == XdmfTopologyType::Wedge_15()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_WEDGE_15;
+ }
+ else if (type->getID() == XdmfTopologyType::Wedge_18()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_WEDGE_18;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_20()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_24()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_27()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_64()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_125()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_216()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_343()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_512()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_729()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_1000()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_1331()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_64()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_125()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_216()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_343()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_512()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_729()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_1000()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_1331()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331;
+ }
+ else if (type->getID() == XdmfTopologyType::Mixed()->getID()) {
+ returnType = XDMF_TOPOLOGY_TYPE_MIXED;
+ }
+ else {
+ returnType = -1;
+ }
+
+ return returnType;
+}
+
+void XdmfTopologySetType(XDMFTOPOLOGY * topology, int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<const XdmfTopologyType> newType = shared_ptr<const XdmfTopologyType>();
+
+ switch (type) {
+ case XDMF_TOPOLOGY_TYPE_POLYVERTEX:
+ newType = XdmfTopologyType::Polyvertex();
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYLINE:
+ newType = XdmfTopologyType::Polyline(0);
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYGON:
+ newType = XdmfTopologyType::Polygon(0);
+ break;
+ case XDMF_TOPOLOGY_TYPE_TRIANGLE:
+ newType = XdmfTopologyType::Triangle();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL:
+ newType = XdmfTopologyType::Quadrilateral();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TETRAHEDRON:
+ newType = XdmfTopologyType::Tetrahedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_PYRAMID:
+ newType = XdmfTopologyType::Pyramid();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE:
+ newType = XdmfTopologyType::Wedge();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON:
+ newType = XdmfTopologyType::Hexahedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_EDGE_3:
+ newType = XdmfTopologyType::Edge_3();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TRIANGLE_6:
+ newType = XdmfTopologyType::Triangle_6();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8:
+ newType = XdmfTopologyType::Quadrilateral_8();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9:
+ newType = XdmfTopologyType::Quadrilateral_9();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10:
+ newType = XdmfTopologyType::Tetrahedron_10();
+ break;
+ case XDMF_TOPOLOGY_TYPE_PYRAMID_13:
+ newType = XdmfTopologyType::Pyramid_13();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE_15:
+ newType = XdmfTopologyType::Wedge_15();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE_18:
+ newType = XdmfTopologyType::Wedge_18();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20:
+ newType = XdmfTopologyType::Hexahedron_20();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24:
+ newType = XdmfTopologyType::Hexahedron_24();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27:
+ newType = XdmfTopologyType::Hexahedron_27();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64:
+ newType = XdmfTopologyType::Hexahedron_64();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125:
+ newType = XdmfTopologyType::Hexahedron_125();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216:
+ newType = XdmfTopologyType::Hexahedron_216();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343:
+ newType = XdmfTopologyType::Hexahedron_343();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512:
+ newType = XdmfTopologyType::Hexahedron_512();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729:
+ newType = XdmfTopologyType::Hexahedron_729();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000:
+ newType = XdmfTopologyType::Hexahedron_1000();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331:
+ newType = XdmfTopologyType::Hexahedron_1331();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64:
+ newType = XdmfTopologyType::Hexahedron_Spectral_64();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125:
+ newType = XdmfTopologyType::Hexahedron_Spectral_125();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216:
+ newType = XdmfTopologyType::Hexahedron_Spectral_216();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343:
+ newType = XdmfTopologyType::Hexahedron_Spectral_343();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512:
+ newType = XdmfTopologyType::Hexahedron_Spectral_512();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729:
+ newType = XdmfTopologyType::Hexahedron_Spectral_729();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000:
+ newType = XdmfTopologyType::Hexahedron_Spectral_1000();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331:
+ newType = XdmfTopologyType::Hexahedron_Spectral_1331();
+ break;
+ case XDMF_TOPOLOGY_TYPE_MIXED:
+ newType = XdmfTopologyType::Mixed();
+ break;
+ default:
+ {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Topology Type: Code " << type;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ break;
+ }
+
+ ((XdmfTopology *)topology)->setType(newType);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfTopologySetPolyType(XDMFTOPOLOGY * topology, int type, int nodes, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<const XdmfTopologyType> newType = shared_ptr<const XdmfTopologyType>();
+
+ switch (type) {
+ case XDMF_TOPOLOGY_TYPE_POLYVERTEX:
+ newType = XdmfTopologyType::Polyvertex();
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYLINE:
+ newType = XdmfTopologyType::Polyline(nodes);
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYGON:
+ newType = XdmfTopologyType::Polygon(nodes);
+ break;
+ case XDMF_TOPOLOGY_TYPE_TRIANGLE:
+ newType = XdmfTopologyType::Triangle();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL:
+ newType = XdmfTopologyType::Quadrilateral();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TETRAHEDRON:
+ newType = XdmfTopologyType::Tetrahedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_PYRAMID:
+ newType = XdmfTopologyType::Pyramid();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE:
+ newType = XdmfTopologyType::Wedge();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON:
+ newType = XdmfTopologyType::Hexahedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_EDGE_3:
+ newType = XdmfTopologyType::Edge_3();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TRIANGLE_6:
+ newType = XdmfTopologyType::Triangle_6();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8:
+ newType = XdmfTopologyType::Quadrilateral_8();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9:
+ newType = XdmfTopologyType::Quadrilateral_9();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10:
+ newType = XdmfTopologyType::Tetrahedron_10();
+ break;
+ case XDMF_TOPOLOGY_TYPE_PYRAMID_13:
+ newType = XdmfTopologyType::Pyramid_13();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE_15:
+ newType = XdmfTopologyType::Wedge_15();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE_18:
+ newType = XdmfTopologyType::Wedge_18();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20:
+ newType = XdmfTopologyType::Hexahedron_20();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24:
+ newType = XdmfTopologyType::Hexahedron_24();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27:
+ newType = XdmfTopologyType::Hexahedron_27();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64:
+ newType = XdmfTopologyType::Hexahedron_64();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125:
+ newType = XdmfTopologyType::Hexahedron_125();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216:
+ newType = XdmfTopologyType::Hexahedron_216();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343:
+ newType = XdmfTopologyType::Hexahedron_343();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512:
+ newType = XdmfTopologyType::Hexahedron_512();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729:
+ newType = XdmfTopologyType::Hexahedron_729();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000:
+ newType = XdmfTopologyType::Hexahedron_1000();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331:
+ newType = XdmfTopologyType::Hexahedron_1331();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64:
+ newType = XdmfTopologyType::Hexahedron_Spectral_64();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125:
+ newType = XdmfTopologyType::Hexahedron_Spectral_125();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216:
+ newType = XdmfTopologyType::Hexahedron_Spectral_216();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343:
+ newType = XdmfTopologyType::Hexahedron_Spectral_343();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512:
+ newType = XdmfTopologyType::Hexahedron_Spectral_512();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729:
+ newType = XdmfTopologyType::Hexahedron_Spectral_729();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000:
+ newType = XdmfTopologyType::Hexahedron_Spectral_1000();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331:
+ newType = XdmfTopologyType::Hexahedron_Spectral_1331();
+ break;
+ case XDMF_TOPOLOGY_TYPE_MIXED:
+ newType = XdmfTopologyType::Mixed();
+ break;
+ default:
+ {
+ std::stringstream sstr;
+ sstr << "Error: Invalid Topology Type: Code " << type;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ break;
+ }
+ ((XdmfTopology *)topology)->setType(newType);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfTopology, XDMFTOPOLOGY)
+XDMF_ARRAY_C_CHILD_WRAPPER(XdmfTopology, XDMFTOPOLOGY)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTopology.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFTOPOLOGY_HPP_
+#define XDMFTOPOLOGY_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfTopologyType.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Holds the connectivity information in an XdmfGrid.
+ *
+ * XdmfTopology is a required part of an XdmfGrid. It stores the
+ * connectivity information for all points contained in an
+ * XdmfGrid. XdmfTopology contains an XdmfTopologyType property which
+ * should be set that specifies the element type stored.
+ *
+ * In the case of mixed topology types, the connectivity stores
+ * topology type ids prior to each element's connectivity
+ * information. For element types of varying sizes (Polyvertex,
+ * Polyline, and Polygon), the topology type id is followed by a
+ * number specifying the number of nodes in the element. For example,
+ * a tetrahedron element (id 6) followed by a polygon element (id 3)
+ * with 5 points would look similar the following:
+ *
+ * 6 20 25 100 200 3 5 300 301 302 303 304
+ *
+ * The tetrahedron is composed of nodes 20, 25, 100, and 200. The
+ * polygon is composed of nodes 300 to 304.
+ *
+ * Elements of type Polyhedron (i.e. N face cells, where each face is a M edge
+ * polygon) are in the following format:
+ * [nCellFaces, nFace0Pts, id0_0, id0_1, ..., nFace1Pts, id1_0, id1_1, ..., ...]
+ */
+class XDMF_EXPORT XdmfTopology : public XdmfArray {
+
+public:
+
+ /**
+ * Create a new XdmfTopology.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopology.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopology.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfTopology.
+ */
+ static shared_ptr<XdmfTopology> New();
+
+ virtual ~XdmfTopology();
+
+ LOKI_DEFINE_VISITABLE(XdmfTopology, XdmfArray)
+ static const std::string ItemTag;
+
+ /**
+ *
+ */
+ int getBaseOffset() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the number of elements this Topology contains.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopology.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getNumberElements
+ * @until //#getNumberElements
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopology.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getNumberElements
+ * @until #//getNumberElements
+ *
+ * @return Int of number elements in the Topology.
+ */
+ virtual unsigned int getNumberElements() const;
+
+ /**
+ * Get the XdmfTopologyType associated with this topology.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopology.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setType
+ * @until //#setType
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopology.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setType
+ * @until #//setType
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * @return XdmfTopologyType of the topology.
+ */
+ shared_ptr<const XdmfTopologyType> getType() const;
+
+ /**
+ *
+ */
+ void setBaseOffset(int offset);
+
+ /**
+ * Set the XdmfTopologyType associated with this topology.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopology.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setType
+ * @until //#setType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopology.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setType
+ * @until #//setType
+ *
+ * @param type The XdmfTopologyType to set.
+ */
+ void setType(const shared_ptr<const XdmfTopologyType> type);
+
+ XdmfTopology(XdmfTopology &);
+
+protected:
+
+ XdmfTopology();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfTopology(const XdmfTopology &); // Not implemented.
+ void operator=(const XdmfTopology &); // Not implemented.
+
+ shared_ptr<const XdmfTopologyType> mType;
+
+ int mBaseOffset;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFTOPOLOGY; // Simply as a typedef to ensure correct typing
+typedef struct XDMFTOPOLOGY XDMFTOPOLOGY;
+
+XDMF_EXPORT XDMFTOPOLOGY * XdmfTopologyNew();
+
+XDMF_EXPORT unsigned int XdmfTopologyGetNumberElements(XDMFTOPOLOGY * topology, int * status);
+
+XDMF_EXPORT int XdmfTopologyGetType(XDMFTOPOLOGY * topology);
+
+XDMF_EXPORT void XdmfTopologySetType(XDMFTOPOLOGY * topology, int type, int * status);
+
+XDMF_EXPORT void XdmfTopologySetPolyType(XDMFTOPOLOGY * topology, int type, int nodes, int * status);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfTopology, XDMFTOPOLOGY, XDMF)
+XDMF_ARRAY_C_CHILD_DECLARE(XdmfTopology, XDMFTOPOLOGY, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFTOPOLOGY_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTopologyType.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <cctype>
+#include <cmath>
+#include <sstream>
+#include <utility>
+#include <vector>
+#include "string.h"
+#include "XdmfError.hpp"
+#include "XdmfTopologyType.hpp"
+
+std::map<std::string, shared_ptr<const XdmfTopologyType>(*)()> XdmfTopologyType::mTopologyDefinitions;
+
+// Supported XdmfTopologyTypes
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::NoTopologyType()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ static shared_ptr<const XdmfTopologyType>
+ /* XdmfTopologyType(numPoints, // if variable will be read from xmf file
+ numFaces,
+ faces,
+ numConnectingLines,
+ TopologyName,
+ Linear/Quadratic/Arbitrary/Structured,
+ CellType)
+ Cell type is denoted by the number after the x
+ */
+ p(new XdmfTopologyType(0, 0, faces, 0, "NoTopology", NoCellType, 0x0));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Polyvertex()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(1, 0, faces, 0, "Polyvertex", Linear, 0x1));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Polyline(const unsigned int nodesPerElement)
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static std::map<unsigned int, shared_ptr<const XdmfTopologyType> >
+ previousTypes;
+ std::map<unsigned int, shared_ptr<const XdmfTopologyType> >::const_iterator
+ type = previousTypes.find(nodesPerElement);
+ if(type != previousTypes.end()) {
+ return type->second;
+ }
+ shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(nodesPerElement, 0, faces, nodesPerElement - 1,
+ "Polyline", Linear, 0x2));
+ previousTypes[nodesPerElement] = p;
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Polygon(const unsigned int nodesPerElement)
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static std::map<unsigned int, shared_ptr<const XdmfTopologyType> >
+ previousTypes;
+ std::map<unsigned int, shared_ptr<const XdmfTopologyType> >::const_iterator
+ type = previousTypes.find(nodesPerElement);
+ if(type != previousTypes.end()) {
+ return type->second;
+ }
+ shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(nodesPerElement, 1, faces, nodesPerElement,
+ "Polygon", Linear, 0x3));
+ previousTypes[nodesPerElement] = p;
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Triangle()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(3, 1, faces, 3, "Triangle", Linear, 0x4));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Quadrilateral()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(4, 1, faces, 4, "Quadrilateral", Linear, 0x5));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Tetrahedron()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::Triangle());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(4, 4, faces, 6, "Tetrahedron", Linear, 0x6));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Pyramid()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(5, 5, faces, 8, "Pyramid", Linear, 0x7));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Wedge()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(6, 5, faces, 9, "Wedge", Linear, 0x8));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::Quadrilateral());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(8, 6, faces, 12, "Hexahedron", Linear, 0x9));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Polyhedron()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(0, 0, faces, 0, "Polyhedron", Linear, 0x10));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Edge_3()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(3, 0, faces, 1, "Edge_3", Quadratic, 0x22));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Triangle_6()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(6, 1, faces, 3, "Triangle_6", Quadratic, 0x24));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Quadrilateral_8()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(8, 1, faces, 4, "Quadrilateral_8", Quadratic, 0x25));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Quadrilateral_9()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(9, 1, faces, 4, "Quadrilateral_9", Quadratic, 0x23));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Tetrahedron_10()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::Triangle_6());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(10, 4, faces, 6, "Tetrahedron_10", Quadratic, 0x26));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Pyramid_13()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(13, 5, faces, 8, "Pyramid_13", Quadratic, 0x27));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Wedge_15()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(15, 5, faces, 9, "Wedge_15", Quadratic, 0x28));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Wedge_18()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(18, 5, faces, 9, "Wedge_18", Quadratic, 0x29));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_20()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::Quadrilateral_8());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(20, 6, faces, 12, "Hexahedron_20", Quadratic, 0x30));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_24()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(24, 6, faces, 12, "Hexahedron_24", Quadratic, 0x31));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_27()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::Quadrilateral_9());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(27, 6, faces, 12, "Hexahedron_27", Quadratic, 0x32));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_64()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(64, 6, faces, 12, "Hexahedron_64", Cubic, 0x33));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_125()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(125, 6, faces, 12, "Hexahedron_125", Quartic, 0x34));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_216()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(216, 6, faces, 12, "Hexahedron_216", Quintic, 0x35));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_343()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(343, 6, faces, 12, "Hexahedron_343", Sextic, 0x36));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_512()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(512, 6, faces, 12, "Hexahedron_512", Septic, 0x37));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_729()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(729, 6, faces, 12, "Hexahedron_729", Octic, 0x38));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_1000()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(1000, 6, faces, 12, "Hexahedron_1000", Nonic, 0x39));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_1331()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(1331, 6, faces, 12, "Hexahedron_1331", Decic, 0x40));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_64()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(64, 6, faces, 12, "Hexahedron_Spectral_64", Cubic, 0x41));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_125()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(125, 6, faces, 12,
+ "Hexahedron_Spectral_125", Quartic, 0x42));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_216()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(216, 6, faces, 12,
+ "Hexahedron_Spectral_216", Quintic, 0x43));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_343()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(343, 6, faces, 12,
+ "Hexahedron_Spectral_343", Sextic, 0x44));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_512()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(512, 6, faces, 12,
+ "Hexahedron_Spectral_512", Septic, 0x45));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_729()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(729, 6, faces, 12,
+ "Hexahedron_Spectral_729", Octic, 0x46));
+ return p;
+}
+
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_1000()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(1000, 6, faces, 12,
+ "Hexahedron_Spectral_1000", Nonic, 0x47));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Hexahedron_Spectral_1331()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ faces.push_back(XdmfTopologyType::NoTopologyType());
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(1331, 6, faces, 12,
+ "Hexahedron_Spectral_1331", Decic, 0x48));
+ return p;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::Mixed()
+{
+ std::vector<shared_ptr<const XdmfTopologyType> > faces;
+ static shared_ptr<const XdmfTopologyType>
+ p(new XdmfTopologyType(0, 0, faces, 0, "Mixed", Arbitrary, 0x70));
+ return p;
+}
+
+void
+XdmfTopologyType::InitTypes()
+{
+ mTopologyDefinitions["NOTOPOLOGY"] = NoTopologyType;
+ mTopologyDefinitions["POLYVERTEX"] = Polyvertex;
+ mTopologyDefinitions["TRIANGLE"] = Triangle;
+ mTopologyDefinitions["QUADRILATERAL"] = Quadrilateral;
+ mTopologyDefinitions["TETRAHEDRON"] = Tetrahedron;
+ mTopologyDefinitions["PYRAMID"] = Pyramid;
+ mTopologyDefinitions["WEDGE"] = Wedge;
+ mTopologyDefinitions["HEXAHEDRON"] = Hexahedron;
+ mTopologyDefinitions["POLYHEDRON"] = Polyhedron;
+ mTopologyDefinitions["EDGE_3"] = Edge_3;
+ mTopologyDefinitions["TRIANGLE_6"] = Triangle_6;
+ mTopologyDefinitions["QUADRILATERAL_8"] = Quadrilateral_8;
+ mTopologyDefinitions["QUADRILATERAL_9"] = Quadrilateral_9;
+ mTopologyDefinitions["TETRAHEDRON_10"] = Tetrahedron_10;
+ mTopologyDefinitions["PYRAMID_13"] = Pyramid_13;
+ mTopologyDefinitions["WEDGE_15"] = Wedge_15;
+ mTopologyDefinitions["WEDGE_18"] = Wedge_18;
+ mTopologyDefinitions["HEXAHEDRON_20"] = Hexahedron_20;
+ mTopologyDefinitions["HEXAHEDRON_24"] = Hexahedron_24;
+ mTopologyDefinitions["HEXAHEDRON_27"] = Hexahedron_27;
+ mTopologyDefinitions["HEXAHEDRON_64"] = Hexahedron_64;
+ mTopologyDefinitions["HEXAHEDRON_125"] = Hexahedron_125;
+ mTopologyDefinitions["HEXAHEDRON_216"] = Hexahedron_216;
+ mTopologyDefinitions["HEXAHEDRON_343"] = Hexahedron_343;
+ mTopologyDefinitions["HEXAHEDRON_512"] = Hexahedron_512;
+ mTopologyDefinitions["HEXAHEDRON_729"] = Hexahedron_729;
+ mTopologyDefinitions["HEXAHEDRON_1000"] = Hexahedron_1000;
+ mTopologyDefinitions["HEXAHEDRON_1331"] = Hexahedron_1331;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_64"] = Hexahedron_Spectral_64;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_125"] = Hexahedron_Spectral_125;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_216"] = Hexahedron_Spectral_216;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_343"] = Hexahedron_Spectral_343;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_512"] = Hexahedron_Spectral_512;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_729"] = Hexahedron_Spectral_729;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_1000"] = Hexahedron_Spectral_1000;
+ mTopologyDefinitions["HEXAHEDRON_SPECTRAL_1331"] = Hexahedron_Spectral_1331;
+ mTopologyDefinitions["MIXED"] = Mixed;
+}
+
+unsigned int
+XdmfTopologyType::calculateHypercubeNumElements(unsigned int numDims,
+ unsigned int elementNumDims) const
+{
+ if (elementNumDims > numDims) {
+ return 0;
+ }
+ else if (elementNumDims == numDims) {
+ return 1;
+ }
+ else {
+ // The calculation has 3 parts
+ // First is the 2 taken to the power of
+ // the object's dimensionality minus the element's dimensionality.
+ unsigned int part1 = std::pow((double)2, (double)(numDims - elementNumDims));
+ // The second part is numDims!/(numDims-elementdims)!
+ unsigned int part2 = 1;
+ for (unsigned int i = numDims; i > (numDims - elementNumDims); --i)
+ {
+ part2 *= i;
+ }
+ // The third part is elementDims!
+ unsigned int part3 = 1;
+ for (unsigned int i = 1; i <= elementNumDims; ++i)
+ {
+ part3 *= i;
+ }
+ return part1 * (part2 / part3);
+ }
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::New(const unsigned int id)
+{
+ if(id == XdmfTopologyType::NoTopologyType()->getID()) {
+ return XdmfTopologyType::NoTopologyType();
+ }
+ else if(id == XdmfTopologyType::Polyvertex()->getID()) {
+ return XdmfTopologyType::Polyvertex();
+ }
+ else if(id == XdmfTopologyType::Polyline(0)->getID()) {
+ return XdmfTopologyType::Polyline(0);
+ }
+ else if(id == XdmfTopologyType::Polygon(0)->getID()) {
+ return XdmfTopologyType::Polygon(0);
+ }
+ else if(id == XdmfTopologyType::Triangle()->getID()) {
+ return XdmfTopologyType::Triangle();
+ }
+ else if(id == XdmfTopologyType::Quadrilateral()->getID()) {
+ return XdmfTopologyType::Quadrilateral();
+ }
+ else if(id == XdmfTopologyType::Tetrahedron()->getID()) {
+ return XdmfTopologyType::Tetrahedron();
+ }
+ else if(id == XdmfTopologyType::Pyramid()->getID()) {
+ return XdmfTopologyType::Pyramid();
+ }
+ else if(id == XdmfTopologyType::Wedge()->getID()) {
+ return XdmfTopologyType::Wedge();
+ }
+ else if(id == XdmfTopologyType::Hexahedron()->getID()) {
+ return XdmfTopologyType::Hexahedron();
+ }
+ else if(id == XdmfTopologyType::Polyhedron()->getID()) {
+ return XdmfTopologyType::Polyhedron();
+ }
+ else if(id == XdmfTopologyType::Edge_3()->getID()) {
+ return XdmfTopologyType::Edge_3();
+ }
+ else if(id == XdmfTopologyType::Triangle_6()->getID()) {
+ return XdmfTopologyType::Triangle_6();
+ }
+ else if(id == XdmfTopologyType::Quadrilateral_8()->getID()) {
+ return XdmfTopologyType::Quadrilateral_8();
+ }
+ else if(id == XdmfTopologyType::Quadrilateral_9()->getID()) {
+ return XdmfTopologyType::Quadrilateral_9();
+ }
+ else if(id == XdmfTopologyType::Tetrahedron_10()->getID()) {
+ return XdmfTopologyType::Tetrahedron_10();
+ }
+ else if(id == XdmfTopologyType::Pyramid_13()->getID()) {
+ return XdmfTopologyType::Pyramid_13();
+ }
+ else if(id == XdmfTopologyType::Wedge_15()->getID()) {
+ return XdmfTopologyType::Wedge_15();
+ }
+ else if(id == XdmfTopologyType::Wedge_18()->getID()) {
+ return XdmfTopologyType::Wedge_18();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_20()->getID()) {
+ return XdmfTopologyType::Hexahedron_20();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_24()->getID()) {
+ return XdmfTopologyType::Hexahedron_24();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_27()->getID()) {
+ return XdmfTopologyType::Hexahedron_27();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_64()->getID()) {
+ return XdmfTopologyType::Hexahedron_64();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_125()->getID()) {
+ return XdmfTopologyType::Hexahedron_125();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_216()->getID()) {
+ return XdmfTopologyType::Hexahedron_216();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_343()->getID()) {
+ return XdmfTopologyType::Hexahedron_343();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_512()->getID()) {
+ return XdmfTopologyType::Hexahedron_512();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_729()->getID()) {
+ return XdmfTopologyType::Hexahedron_729();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_1000()->getID()) {
+ return XdmfTopologyType::Hexahedron_1000();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_1331()->getID()) {
+ return XdmfTopologyType::Hexahedron_1331();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_64()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_64();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_125()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_125();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_216()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_216();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_343()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_343();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_512()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_512();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_729()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_729();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_1000()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_1000();
+ }
+ else if(id == XdmfTopologyType::Hexahedron_Spectral_1331()->getID()) {
+ return XdmfTopologyType::Hexahedron_Spectral_1331();
+ }
+ else if(id == XdmfTopologyType::Mixed()->getID()) {
+ return XdmfTopologyType::Mixed();
+ }
+ return shared_ptr<const XdmfTopologyType>();
+}
+
+XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement,
+ const unsigned int facesPerElement,
+ const std::vector<shared_ptr<const XdmfTopologyType> > & faces,
+ const unsigned int edgesPerElement,
+ const std::string & name,
+ const CellType cellType,
+ const unsigned int id) :
+ mCellType(cellType),
+ mEdgesPerElement(edgesPerElement),
+ mFacesPerElement(facesPerElement),
+ mFaces(faces),
+ mID(id),
+ mName(name),
+ mNodesPerElement(nodesPerElement)
+{
+}
+
+XdmfTopologyType::~XdmfTopologyType()
+{
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("Type");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("TopologyType");
+ }
+ if(type == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Neither 'Type' nor 'TopologyType' found in "
+ "itemProperties in XdmfTopologyType::New");
+ }
+ std::string typeVal = ConvertToUpper(type->second);
+
+ std::map<std::string, std::string>::const_iterator nodesPerElement =
+ itemProperties.find("NodesPerElement");
+
+ std::map<std::string, shared_ptr<const XdmfTopologyType>(*)()>::const_iterator returnType
+ = mTopologyDefinitions.find(typeVal);
+
+ if (returnType == mTopologyDefinitions.end()) {
+ if(typeVal.compare("POLYLINE") == 0) {
+ if(nodesPerElement != itemProperties.end()) {
+ return Polyline(atoi(nodesPerElement->second.c_str()));
+ }
+ XdmfError::message(XdmfError::FATAL,
+ "'NodesPerElement' not in itemProperties and type "
+ "'POLYLINE' selected in XdmfTopologyType::New");
+ }
+ else if(typeVal.compare("POLYGON") == 0) {
+ if(nodesPerElement != itemProperties.end()) {
+ return Polygon(atoi(nodesPerElement->second.c_str()));
+ }
+ XdmfError::message(XdmfError::FATAL,
+ "'NodesPerElement' not in itemProperties and type "
+ "'POLYGON' selected in XdmfTopologyType::New");
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Invalid Type selected in XdmfTopologyType::New");
+
+ }
+ }
+ else {
+ return (*(returnType->second))();
+ }
+
+ XdmfError::message(XdmfError::FATAL,
+ "Invalid Type selected in XdmfTopologyType::New");
+
+ // unreachable
+ return shared_ptr<const XdmfTopologyType>();
+}
+
+XdmfTopologyType::CellType
+XdmfTopologyType::getCellType() const
+{
+ return mCellType;
+}
+
+unsigned int
+XdmfTopologyType::getEdgesPerElement() const
+{
+ return mEdgesPerElement;
+}
+
+shared_ptr<const XdmfTopologyType>
+XdmfTopologyType::getFaceType() const
+{
+ if (mFaces.size() == 0) {
+ return XdmfTopologyType::NoTopologyType();
+ }
+ else {
+ return mFaces[0];
+ }
+}
+
+unsigned int
+XdmfTopologyType::getFacesPerElement() const
+{
+ return mFacesPerElement;
+}
+
+unsigned int
+XdmfTopologyType::getID() const
+{
+ return mID;
+}
+
+std::string
+XdmfTopologyType::getName() const
+{
+ return mName;
+}
+
+unsigned int
+XdmfTopologyType::getNodesPerElement() const
+{
+ return mNodesPerElement;
+}
+
+void
+XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("Type", this->getName()));
+ if(mName.compare("Polygon") == 0 || mName.compare("Polyline") == 0) {
+ std::stringstream nodesPerElement;
+ nodesPerElement << mNodesPerElement;
+ collectedProperties.insert(std::make_pair("NodesPerElement",
+ nodesPerElement.str()));
+ }
+}
+
+// C Wrappers
+
+int XdmfTopologyTypePolyvertex()
+{
+ return XDMF_TOPOLOGY_TYPE_POLYVERTEX;
+}
+
+int XdmfTopologyTypePolyline()
+{
+ return XDMF_TOPOLOGY_TYPE_POLYLINE;
+}
+
+int XdmfTopologyTypePolygon()
+{
+ return XDMF_TOPOLOGY_TYPE_POLYGON;
+}
+
+int XdmfTopologyTypeTriangle()
+{
+ return XDMF_TOPOLOGY_TYPE_TRIANGLE;
+}
+
+int XdmfTopologyTypeQuadrilateral()
+{
+ return XDMF_TOPOLOGY_TYPE_QUADRILATERAL;
+}
+
+int XdmfTopologyTypeTetrahedron()
+{
+ return XDMF_TOPOLOGY_TYPE_TETRAHEDRON;
+}
+
+int XdmfTopologyTypePyramid()
+{
+ return XDMF_TOPOLOGY_TYPE_PYRAMID;
+}
+
+int XdmfTopologyTypeWedge()
+{
+ return XDMF_TOPOLOGY_TYPE_WEDGE;
+}
+
+int XdmfTopologyTypeHexahedron()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON;
+}
+
+int XdmfTopologyTypePolyhedron()
+{
+ return XDMF_TOPOLOGY_TYPE_POLYHEDRON;
+}
+
+int XdmfTopologyTypeEdge_3()
+{
+ return XDMF_TOPOLOGY_TYPE_EDGE_3;
+}
+
+int XdmfTopologyTypeTriangle_6()
+{
+ return XDMF_TOPOLOGY_TYPE_TRIANGLE_6;
+}
+
+int XdmfTopologyTypeQuadrilateral_8()
+{
+ return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8;
+}
+
+int XdmfTopologyTypeQuadrilateral_9()
+{
+ return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9;
+}
+
+int XdmfTopologyTypeTetrahedron_10()
+{
+ return XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10;
+}
+
+int XdmfTopologyTypePyramid_13()
+{
+ return XDMF_TOPOLOGY_TYPE_PYRAMID_13;
+}
+
+int XdmfTopologyTypeWedge_15()
+{
+ return XDMF_TOPOLOGY_TYPE_WEDGE_15;
+}
+
+int XdmfTopologyTypeWedge_18()
+{
+ return XDMF_TOPOLOGY_TYPE_WEDGE_18;
+}
+
+int XdmfTopologyTypeHexahedron_20()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20;
+}
+
+int XdmfTopologyTypeHexahedron_24()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24;
+}
+
+int XdmfTopologyTypeHexahedron_27()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27;
+}
+
+int XdmfTopologyTypeHexahedron_64()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64;
+}
+
+int XdmfTopologyTypeHexahedron_125()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125;
+}
+
+int XdmfTopologyTypeHexahedron_216()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216;
+}
+
+int XdmfTopologyTypeHexahedron_343()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343;
+}
+
+int XdmfTopologyTypeHexahedron_512()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512;
+}
+
+int XdmfTopologyTypeHexahedron_729()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729;
+}
+
+int XdmfTopologyTypeHexahedron_1000()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000;
+}
+
+int XdmfTopologyTypeHexahedron_1331()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_64()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_125()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_216()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_343()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_512()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_729()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_1000()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000;
+}
+
+int XdmfTopologyTypeHexahedron_Spectral_1331()
+{
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331;
+}
+
+int XdmfTopologyTypeMixed()
+{
+ return XDMF_TOPOLOGY_TYPE_MIXED;
+}
+
+shared_ptr<const XdmfTopologyType> intToType(int type, int nodes = 0)
+{
+ switch (type) {
+ case XDMF_TOPOLOGY_TYPE_POLYVERTEX:
+ return XdmfTopologyType::Polyvertex();
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYLINE:
+ return XdmfTopologyType::Polyline(nodes);
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYGON:
+ return XdmfTopologyType::Polygon(nodes);
+ break;
+ case XDMF_TOPOLOGY_TYPE_TRIANGLE:
+ return XdmfTopologyType::Triangle();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL:
+ return XdmfTopologyType::Quadrilateral();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TETRAHEDRON:
+ return XdmfTopologyType::Tetrahedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_PYRAMID:
+ return XdmfTopologyType::Pyramid();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE:
+ return XdmfTopologyType::Wedge();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON:
+ return XdmfTopologyType::Hexahedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_POLYHEDRON:
+ return XdmfTopologyType::Polyhedron();
+ break;
+ case XDMF_TOPOLOGY_TYPE_EDGE_3:
+ return XdmfTopologyType::Edge_3();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TRIANGLE_6:
+ return XdmfTopologyType::Triangle_6();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8:
+ return XdmfTopologyType::Quadrilateral_8();
+ break;
+ case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9:
+ return XdmfTopologyType::Quadrilateral_9();
+ break;
+ case XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10:
+ return XdmfTopologyType::Tetrahedron_10();
+ break;
+ case XDMF_TOPOLOGY_TYPE_PYRAMID_13:
+ return XdmfTopologyType::Pyramid_13();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE_15:
+ return XdmfTopologyType::Wedge_15();
+ break;
+ case XDMF_TOPOLOGY_TYPE_WEDGE_18:
+ return XdmfTopologyType::Wedge_18();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20:
+ return XdmfTopologyType::Hexahedron_20();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24:
+ return XdmfTopologyType::Hexahedron_24();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27:
+ return XdmfTopologyType::Hexahedron_27();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64:
+ return XdmfTopologyType::Hexahedron_64();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125:
+ return XdmfTopologyType::Hexahedron_125();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216:
+ return XdmfTopologyType::Hexahedron_216();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343:
+ return XdmfTopologyType::Hexahedron_343();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512:
+ return XdmfTopologyType::Hexahedron_512();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729:
+ return XdmfTopologyType::Hexahedron_729();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000:
+ return XdmfTopologyType::Hexahedron_1000();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331:
+ return XdmfTopologyType::Hexahedron_1331();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64:
+ return XdmfTopologyType::Hexahedron_Spectral_64();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125:
+ return XdmfTopologyType::Hexahedron_Spectral_125();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216:
+ return XdmfTopologyType::Hexahedron_Spectral_216();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343:
+ return XdmfTopologyType::Hexahedron_Spectral_343();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512:
+ return XdmfTopologyType::Hexahedron_Spectral_512();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729:
+ return XdmfTopologyType::Hexahedron_Spectral_729();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000:
+ return XdmfTopologyType::Hexahedron_Spectral_1000();
+ break;
+ case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331:
+ return XdmfTopologyType::Hexahedron_Spectral_1331();
+ break;
+ case XDMF_TOPOLOGY_TYPE_MIXED:
+ return XdmfTopologyType::Mixed();
+ break;
+ default:
+ return shared_ptr<const XdmfTopologyType>();
+ break;
+ }
+}
+
+int typeToInt(shared_ptr<const XdmfTopologyType> type)
+{
+ if (type->getID() == XdmfTopologyType::Polyvertex()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_POLYVERTEX;
+ }
+ else if (type->getID() == XdmfTopologyType::Polyline(0)->getID()) {
+ return XDMF_TOPOLOGY_TYPE_POLYLINE;
+ }
+ else if (type->getID() == XdmfTopologyType::Polygon(0)->getID()) {
+ return XDMF_TOPOLOGY_TYPE_POLYGON;
+ }
+ else if (type->getID() == XdmfTopologyType::Triangle()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_TRIANGLE;
+ }
+ else if (type->getID() == XdmfTopologyType::Quadrilateral()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_QUADRILATERAL;
+ }
+ else if (type->getID() == XdmfTopologyType::Tetrahedron()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_TETRAHEDRON;
+ }
+ else if (type->getID() == XdmfTopologyType::Pyramid()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_PYRAMID;
+ }
+ else if (type->getID() == XdmfTopologyType::Wedge()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_WEDGE;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON;
+ }
+ else if (type->getID() == XdmfTopologyType::Polyhedron()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_POLYHEDRON;
+ }
+ else if (type->getID() == XdmfTopologyType::Edge_3()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_EDGE_3;
+ }
+ else if (type->getID() == XdmfTopologyType::Triangle_6()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_TRIANGLE_6;
+ }
+ else if (type->getID() == XdmfTopologyType::Quadrilateral_8()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8;
+ }
+ else if (type->getID() == XdmfTopologyType::Quadrilateral_9()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9;
+ }
+ else if (type->getID() == XdmfTopologyType::Tetrahedron_10()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10;
+ }
+ else if (type->getID() == XdmfTopologyType::Pyramid_13()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_PYRAMID_13;
+ }
+ else if (type->getID() == XdmfTopologyType::Wedge_15()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_WEDGE_15;
+ }
+ else if (type->getID() == XdmfTopologyType::Wedge_18()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_WEDGE_18;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_20()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_24()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_27()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_64()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_125()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_216()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_343()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_512()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_729()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_1000()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_1331()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_64()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_125()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_216()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_343()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_512()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_729()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_1000()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000;
+ }
+ else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_1331()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331;
+ }
+ else if (type->getID() == XdmfTopologyType::Mixed()->getID()) {
+ return XDMF_TOPOLOGY_TYPE_MIXED;
+ }
+ else {
+ return -1;
+ }
+}
+
+int XdmfTopologyTypeGetCellType(int type)
+{
+ return intToType(type)->getCellType();
+}
+
+unsigned int XdmfTopologyTypeGetEdgesPerElement(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return intToType(type)->getEdgesPerElement();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+unsigned int XdmfTopologyTypeGetFacesPerElement(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return intToType(type)->getFacesPerElement();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+int XdmfTopologyTypeGetFaceType(int type)
+{
+ return typeToInt(intToType(type)->getFaceType());
+}
+
+unsigned int XdmfTopologyTypeGetID(int type)
+{
+ return intToType(type)->getID();
+}
+
+char * XdmfTopologyTypeGetName(int type)
+{
+ char * returnPointer = strdup(intToType(type)->getName().c_str());
+ return returnPointer;
+}
+
+unsigned int XdmfTopologyTypeGetNodesPerElement(int type)
+{
+ return intToType(type)->getNodesPerElement();
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTopologyType.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFTOPOLOGYTYPE_HPP_
+#define XDMFTOPOLOGYTYPE_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include "XdmfItemProperty.hpp"
+#include <map>
+#include <vector>
+
+/**
+ * @brief Property describing the types of elements stored in an
+ * XdmfTopology.
+ *
+ * XdmfTopologyType is a property used by XdmfTopology to specify the
+ * element types stored. A specific XdmfTopologyType can be created by
+ * calling one of the static methods in the class,
+ * i.e. XdmfTopologyType::Tetrahedron().
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * Xdmf supports the following topology types:
+ * NoTopologyType
+ * Polyvertex - Unconnected Points
+ * Polyline - Line Segments
+ * Polygon - N Edge Polygon
+ * Triangle - 3 Edge Polygon
+ * Quadrilateral - 4 Edge Polygon
+ * Tetrahedron - 4 Triangular Faces
+ * Wedge - 4 Triangular Faces, Quadrilateral Base
+ * Hexahedron - 6 Quadrilateral Faces
+ * Polyhedron - N Face Cell, where each Face is a M Edge Polygon
+ * Edge_3 - 3 Node Quadratic Line
+ * Triangle_6 - 6 Node Quadratic Triangle
+ * Quadrilateral_8 - 8 Node Quadratic Quadrilateral
+ * Quadrilateral_9 - 9 Node Bi-Quadratic Quadrilateral
+ * Tetrahedron_10 - 10 Node Quadratic Tetrahedron
+ * Pyramid_13 - 13 Node Quadratic Pyramid
+ * Wedge_15 - 15 Node Quadratic Wedge
+ * Wedge_18 - 18 Node Bi-Quadratic Wedge
+ * Hexahedron_20 - 20 Node Quadratic Hexahedron
+ * Hexahedron_24 - 24 Node Bi-Quadratic Hexahedron
+ * Hexahedron_27 - 27 Node Tri-Quadratic Hexahedron
+ * Hexahedron_64 - 64 Node Tri-Cubic Hexahedron
+ * Hexahedron_125 - 125 Node Tri-Quartic Hexahedron
+ * Hexahedron_216 - 216 Node Tri-Quintic Hexahedron
+ * Hexahedron_343 - 343 Node Tri-Hexic Hexahedron
+ * Hexahedron_512 - 512 Node Tri-Septic Hexahedron
+ * Hexahedron_729 - 729 Node Tri-Octic Hexahedron
+ * Hexahedron_1000 - 1000 Node Tri-Nonic Hexahedron
+ * Hexahedron_1331 - 1331 Node Tri-Decic Hexahedron
+ * Hexahedron_Spectral_64 - 64 Node Spectral Tri-Cubic Hexahedron
+ * Hexahedron_Spectral_125 - 125 Node Spectral Tri-Quartic Hexahedron
+ * Hexahedron_Spectral_216 - 216 Node Spectral Tri-Quintic Hexahedron
+ * Hexahedron_Spectral_343 - 343 Node Spectral Tri-Hexic Hexahedron
+ * Hexahedron_Spectral_512 - 512 Node Spectral Tri-Septic Hexahedron
+ * Hexahedron_Spectral_729 - 729 Node Spectral Tri-Octic Hexahedron
+ * Hexahedron_Spectral_1000 - 1000 Node Spectral Tri-Nonic Hexahedron
+ * Hexahedron_Spectral_1331 - 1331 Node Spectral Tri-Decic Hexahedron
+ * Mixed - Mixture of Unstructured Topologies
+ */
+class XDMF_EXPORT XdmfTopologyType : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfTopologyType();
+
+ friend class XdmfTopology;
+
+ enum CellType {
+ NoCellType = 0,
+ Linear = 1,
+ Quadratic = 2,
+ Cubic = 3,
+ Quartic = 4,
+ Quintic = 5,
+ Sextic = 6,
+ Septic = 7,
+ Octic = 8,
+ Nonic = 9,
+ Decic = 10,
+ Arbitrary = 100,
+ Structured = 101
+ };
+
+ /**
+ * Supported Xdmf Topology Types
+ */
+ static shared_ptr<const XdmfTopologyType> NoTopologyType();
+ static shared_ptr<const XdmfTopologyType> Polyvertex();
+ static shared_ptr<const XdmfTopologyType>
+ Polyline(const unsigned int nodesPerElement);
+ static shared_ptr<const XdmfTopologyType>
+ Polygon(const unsigned int nodesPerElement);
+ static shared_ptr<const XdmfTopologyType> Triangle();
+ static shared_ptr<const XdmfTopologyType> Quadrilateral();
+ static shared_ptr<const XdmfTopologyType> Tetrahedron();
+ static shared_ptr<const XdmfTopologyType> Pyramid();
+ static shared_ptr<const XdmfTopologyType> Wedge();
+ static shared_ptr<const XdmfTopologyType> Hexahedron();
+ static shared_ptr<const XdmfTopologyType> Polyhedron();
+ static shared_ptr<const XdmfTopologyType> Edge_3();
+ static shared_ptr<const XdmfTopologyType> Triangle_6();
+ static shared_ptr<const XdmfTopologyType> Quadrilateral_8();
+ static shared_ptr<const XdmfTopologyType> Quadrilateral_9();
+ static shared_ptr<const XdmfTopologyType> Tetrahedron_10();
+ static shared_ptr<const XdmfTopologyType> Pyramid_13();
+ static shared_ptr<const XdmfTopologyType> Wedge_15();
+ static shared_ptr<const XdmfTopologyType> Wedge_18();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_20();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_24();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_27();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_64();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_125();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_216();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_343();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_512();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_729();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_1000();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_1331();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_64();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_125();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_216();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_343();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_512();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_729();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_1000();
+ static shared_ptr<const XdmfTopologyType> Hexahedron_Spectral_1331();
+ static shared_ptr<const XdmfTopologyType> Mixed();
+
+ /**
+ * Get a topology type from id.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param id of the topology type.
+ *
+ * @return Topology type corresponding to id - if no topology type is found
+ * an NULL pointer is returned.
+ */
+ static shared_ptr<const XdmfTopologyType> New(const unsigned int id);
+
+ /**
+ * Get the cell type associated with this topology type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getCellType
+ * @until //#getCellType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getCellType
+ * @until #//getCellType
+ *
+ * @return A CellType containing the cell type.
+ */
+ CellType getCellType() const;
+
+ /**
+ * Get the number of edges per element associated with this topology type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getEdgesPerElement
+ * @until //#getEdgesPerElement
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getEdgesPerElement
+ * @until #//getEdgesPerElement
+ *
+ * @return An unsigned int containing the number of edges per element.
+ */
+ virtual unsigned int getEdgesPerElement() const;
+
+ /**
+ * Get the number of faces per element associated with this topology type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getFacesPerElement
+ * @until //#getFacesPerElement
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getFacesPerElement
+ * @until #//getFacesPerElement
+ *
+ * @return An unsigned int containing the number of faces per element.
+ */
+ virtual unsigned int getFacesPerElement() const;
+
+ /**
+ * Gets the type of the faces of the topology.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getFaceType
+ * @until //#getFaceType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getFaceType
+ * @until #//getFaceType
+ *
+ * @return The face's topology type
+ */
+ shared_ptr<const XdmfTopologyType> getFaceType() const;
+
+ /**
+ * Get the id of this cell type, necessary in order to create grids
+ * containing mixed cells.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getID
+ * @until //#getID
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline //#getID
+ * @until //#getID
+ *
+ * @return The ID of the topology type.
+ */
+ virtual unsigned int getID() const;
+
+ /**
+ * Get the name of this topology type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return The name of this topology type.
+ */
+ virtual std::string getName() const;
+
+ /**
+ * Get the number of nodes per element associated with this topology
+ * type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTopologyType.cpp
+ * @skipline //#getNodesPerElement
+ * @until //#getNodesPerElement
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTopologyType.py
+ * @skipline #//getNodesPerElement
+ * @until #//getNodesPerElement
+ *
+ * @return An unsigned int containing number of nodes per element.
+ */
+ virtual unsigned int getNodesPerElement() const;
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+protected:
+
+ /**
+ * Protected constructor for XdmfTopologyType. The constructor is
+ * protected because all topology types supported by Xdmf should be
+ * accessed through more specific static methods that construct
+ * XdmfTopologyType - i.e. XdmfTopologyType::Tetrahedron()
+ */
+ XdmfTopologyType(const unsigned int nodesPerElement,
+ const unsigned int facesPerElement,
+ const std::vector<shared_ptr<const XdmfTopologyType> > & faces,
+ const unsigned int edgesPerElement,
+ const std::string & name,
+ const CellType cellType,
+ const unsigned int id);
+
+ unsigned int calculateHypercubeNumElements(unsigned int numDims, unsigned int elementNumDims) const;
+
+ static std::map<std::string, shared_ptr<const XdmfTopologyType>(*)()> mTopologyDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfTopologyType(const XdmfTopologyType &); // Not implemented.
+ void operator=(const XdmfTopologyType &); // Not implemented.
+
+ static shared_ptr<const XdmfTopologyType>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ const CellType mCellType;
+ const unsigned int mEdgesPerElement;
+ const unsigned int mFacesPerElement;
+ std::vector<shared_ptr<const XdmfTopologyType> > mFaces;
+ const unsigned int mID;
+ const std::string mName;
+ const unsigned int mNodesPerElement;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#ifndef XDMF_C_TOPOLOGY_TYPES
+#define XDMF_C_TOPOLOGY_TYPES
+#define XDMF_TOPOLOGY_TYPE_POLYVERTEX 500
+#define XDMF_TOPOLOGY_TYPE_POLYLINE 501
+#define XDMF_TOPOLOGY_TYPE_POLYGON 502
+#define XDMF_TOPOLOGY_TYPE_POLYHEDRON 503
+#define XDMF_TOPOLOGY_TYPE_TRIANGLE 504
+#define XDMF_TOPOLOGY_TYPE_QUADRILATERAL 505
+#define XDMF_TOPOLOGY_TYPE_TETRAHEDRON 506
+#define XDMF_TOPOLOGY_TYPE_PYRAMID 507
+#define XDMF_TOPOLOGY_TYPE_WEDGE 508
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON 509
+#define XDMF_TOPOLOGY_TYPE_EDGE_3 510
+#define XDMF_TOPOLOGY_TYPE_TRIANGLE_6 511
+#define XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8 512
+#define XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9 513
+#define XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10 514
+#define XDMF_TOPOLOGY_TYPE_PYRAMID_13 515
+#define XDMF_TOPOLOGY_TYPE_WEDGE_15 516
+#define XDMF_TOPOLOGY_TYPE_WEDGE_18 517
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20 518
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24 519
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27 520
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64 521
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125 522
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216 523
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343 524
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512 525
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729 526
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000 527
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331 528
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64 529
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125 530
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216 531
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343 532
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512 533
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729 534
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000 535
+#define XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331 536
+#define XDMF_TOPOLOGY_TYPE_MIXED 537
+#endif
+
+#define XDMF_TOPOLOGY_CELL_TYPE_NO_CELL_TYPE 0
+#define XDMF_TOPOLOGY_CELL_TYPE_LINEAR 1
+#define XDMF_TOPOLOGY_CELL_TYPE_QUADRATIC 2
+#define XDMF_TOPOLOGY_CELL_TYPE_CUBIC 3
+#define XDMF_TOPOLOGY_CELL_TYPE_QUARTIC 4
+#define XDMF_TOPOLOGY_CELL_TYPE_QUINTIC 5
+#define XDMF_TOPOLOGY_CELL_TYPE_SEXTIC 6
+#define XDMF_TOPOLOGY_CELL_TYPE_SEPTIC 7
+#define XDMF_TOPOLOGY_CELL_TYPE_OCTIC 8
+#define XDMF_TOPOLOGY_CELL_TYPE_NONIC 9
+#define XDMF_TOPOLOGY_CELL_TYPE_DECIC 10
+#define XDMF_TOPOLOGY_CELL_TYPE_ARBITRARY 100
+#define XDMF_TOPOLOGY_CELL_TYPE_STRUCTURED 101
+
+XDMF_EXPORT int XdmfTopologyTypePolyvertex();
+XDMF_EXPORT int XdmfTopologyTypePolyline();
+XDMF_EXPORT int XdmfTopologyTypePolygon();
+XDMF_EXPORT int XdmfTopologyTypeTriangle();
+XDMF_EXPORT int XdmfTopologyTypeQuadrilateral();
+XDMF_EXPORT int XdmfTopologyTypeTetrahedron();
+XDMF_EXPORT int XdmfTopologyTypePyramid();
+XDMF_EXPORT int XdmfTopologyTypeWedge();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron();
+XDMF_EXPORT int XdmfTopologyTypeEdge_3();
+XDMF_EXPORT int XdmfTopologyTypeTriangle_6();
+XDMF_EXPORT int XdmfTopologyTypeQuadrilateral_8();
+XDMF_EXPORT int XdmfTopologyTypeQuadrilateral_9();
+XDMF_EXPORT int XdmfTopologyTypeTetrahedron_10();
+XDMF_EXPORT int XdmfTopologyTypePyramid_13();
+XDMF_EXPORT int XdmfTopologyTypeWedge_15();
+XDMF_EXPORT int XdmfTopologyTypeWedge_18();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_20();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_24();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_27();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_64();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_125();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_216();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_343();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_512();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_729();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_1000();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_1331();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_64();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_125();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_216();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_343();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_512();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_729();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_1000();
+XDMF_EXPORT int XdmfTopologyTypeHexahedron_Spectral_1331();
+XDMF_EXPORT int XdmfTopologyTypeMixed();
+
+
+XDMF_EXPORT int XdmfTopologyTypeGetCellType(int type);
+
+XDMF_EXPORT unsigned int XdmfTopologyTypeGetEdgesPerElement(int type, int * status);
+
+XDMF_EXPORT unsigned int XdmfTopologyTypeGetFacesPerElement(int type, int * status);
+
+XDMF_EXPORT int XdmfTopologyTypeGetFaceType(int type);
+
+XDMF_EXPORT unsigned int XdmfTopologyTypeGetID(int type);
+
+XDMF_EXPORT char * XdmfTopologyTypeGetName(int type);
+
+XDMF_EXPORT unsigned int XdmfTopologyTypeGetNodesPerElement(int type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFTOPOLOGYTYPE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfUnstructuredGrid.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfError.hpp"
+#include "XdmfGeometry.hpp"
+#include "XdmfGeometryType.hpp"
+#include "XdmfRegularGrid.hpp"
+#include "XdmfTopology.hpp"
+#include "XdmfTopologyType.hpp"
+#include "XdmfUnstructuredGrid.hpp"
+
+/**
+ * local functions
+ */
+namespace {
+
+ void
+ convertRegularGeometry(unsigned int index,
+ shared_ptr<XdmfArray> point,
+ shared_ptr<XdmfArray> dimensions,
+ shared_ptr<XdmfArray> brickSize,
+ shared_ptr<XdmfArray> mGeometry) {
+
+ const unsigned int nDim = dimensions->getValue<unsigned int>(index);
+ const double nBrickSize = brickSize->getValue<double>(index);
+ const double originalPoint = point->getValue<double>(index);
+
+ for(unsigned int i=0; i<nDim; ++i) {
+ if(index == 0) {
+ mGeometry->insert(mGeometry->getSize(),
+ point,
+ 0,
+ point->getSize());
+ }
+ else {
+ convertRegularGeometry(index - 1,
+ point,
+ dimensions,
+ brickSize,
+ mGeometry);
+ }
+ const double currPoint = point->getValue<double>(index);
+ point->insert(index, currPoint + nBrickSize);
+ }
+
+ point->insert(index, originalPoint);
+ }
+
+ void
+ convertRegularTopology(shared_ptr<XdmfArray> dimensions,
+ shared_ptr<XdmfArray> mTopology)
+ {
+
+ if(dimensions->getSize() == 2) {
+ const unsigned int nx = dimensions->getValue<unsigned int>(0);
+ const unsigned int ny = dimensions->getValue<unsigned int>(1);
+ unsigned int offset = 0;
+ for(unsigned int i=1; i<ny; ++i) {
+ for(unsigned int j=1; j<nx; ++j) {
+ mTopology->pushBack<unsigned int>(offset);
+ mTopology->pushBack<unsigned int>(offset + 1);
+ mTopology->pushBack<unsigned int>(offset + nx + 1);
+ mTopology->pushBack<unsigned int>(offset + nx);
+ ++offset;
+ }
+ ++offset;
+ }
+ }
+ else if(dimensions->getSize() == 3) {
+ const unsigned int nx = dimensions->getValue<unsigned int>(0);
+ const unsigned int ny = dimensions->getValue<unsigned int>(1);
+ const unsigned int nz = dimensions->getValue<unsigned int>(2);
+ const unsigned int zOffset = nx * ny;
+ unsigned int offset = 0;
+ for(unsigned int i=1; i<nz; ++i) {
+ for(unsigned int j=1; j<ny; ++j) {
+ for(unsigned int k=1; k<nx; ++k) {
+ mTopology->pushBack<unsigned int>(offset);
+ mTopology->pushBack<unsigned int>(offset + 1);
+ mTopology->pushBack<unsigned int>(offset + nx + 1);
+ mTopology->pushBack<unsigned int>(offset + nx);
+ mTopology->pushBack<unsigned int>(offset + zOffset);
+ mTopology->pushBack<unsigned int>(offset + zOffset + 1);
+ mTopology->pushBack<unsigned int>(offset + zOffset + nx + 1);
+ mTopology->pushBack<unsigned int>(offset + zOffset + nx);
+ ++offset;
+ }
+ ++offset;
+ }
+ offset += nx;
+ }
+ }
+ }
+}
+
+class XdmfUnstructuredGrid::XdmfUnstructuredGridImpl : public XdmfGridImpl
+{
+ public:
+ XdmfUnstructuredGridImpl()
+ {
+ mGridType = "Unstructured";
+ }
+
+ ~XdmfUnstructuredGridImpl()
+ {
+ }
+
+ XdmfGridImpl * duplicate()
+ {
+ return new XdmfUnstructuredGridImpl();
+ }
+
+ std::string getGridType() const
+ {
+ return mGridType;
+ }
+};
+
+shared_ptr<XdmfUnstructuredGrid>
+XdmfUnstructuredGrid::New()
+{
+ shared_ptr<XdmfUnstructuredGrid> p(new XdmfUnstructuredGrid());
+ return p;
+}
+
+shared_ptr<XdmfUnstructuredGrid>
+XdmfUnstructuredGrid::New(const shared_ptr<XdmfRegularGrid> regularGrid)
+{
+ shared_ptr<XdmfUnstructuredGrid> p(new XdmfUnstructuredGrid(regularGrid));
+ return p;
+}
+
+XdmfUnstructuredGrid::XdmfUnstructuredGrid() :
+ XdmfGrid(XdmfGeometry::New(), XdmfTopology::New())
+{
+ mImpl = new XdmfUnstructuredGridImpl();
+}
+
+XdmfUnstructuredGrid::XdmfUnstructuredGrid(const shared_ptr<XdmfRegularGrid> regularGrid) :
+ XdmfGrid(XdmfGeometry::New(), XdmfTopology::New())
+{
+ mImpl = new XdmfUnstructuredGridImpl();
+
+ const shared_ptr<XdmfArray> origin = regularGrid->getOrigin();
+
+ shared_ptr<XdmfArray> brickSize = regularGrid->getBrickSize();
+ shared_ptr<XdmfArray> dimensions = regularGrid->getDimensions();
+
+ if(dimensions->getSize() != brickSize->getSize() ||
+ dimensions->getSize() != origin->getSize()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Inconsistent brick, dimension, and origin sizes when"
+ "converting regular grid to unstructured grid in "
+ "XdmfUnstructuredGrid constructor");
+ }
+
+ bool releaseOrigin = false;
+ bool releaseBrickSize = false;
+ bool releaseDimensions = false;
+ if(!origin->isInitialized()) {
+ origin->read();
+ releaseOrigin = true;
+ }
+ if(!brickSize->isInitialized()) {
+ brickSize->read();
+ releaseBrickSize = true;
+ }
+ if(!dimensions->isInitialized()) {
+ dimensions->read();
+ releaseDimensions = true;
+ }
+
+ shared_ptr<const XdmfGeometryType> geometryType;
+ shared_ptr<const XdmfTopologyType> topologyType;
+ if(origin->getSize() == 2) {
+ geometryType = XdmfGeometryType::XY();
+ topologyType = XdmfTopologyType::Quadrilateral();
+ }
+ else if(origin->getSize() == 3) {
+ geometryType = XdmfGeometryType::XYZ();
+ topologyType = XdmfTopologyType::Hexahedron();
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Cannot convert regular grid of dimensions not 2 or 3 "
+ "to XdmfUnstructuredGrid in XdmfUnstructuredGrid "
+ "constructor");
+ }
+ mGeometry->setType(geometryType);
+ mTopology->setType(topologyType);
+
+ shared_ptr<XdmfArray> point = XdmfArray::New();
+ point->insert(0, origin, 0, origin->getSize());
+ convertRegularGeometry(dimensions->getSize() - 1,
+ point,
+ dimensions,
+ brickSize,
+ mGeometry);
+ convertRegularTopology(dimensions,
+ mTopology);
+
+ if(releaseOrigin) {
+ origin->release();
+ }
+ if(releaseBrickSize) {
+ brickSize->release();
+ }
+ if(releaseDimensions) {
+ dimensions->release();
+ }
+}
+
+XdmfUnstructuredGrid::XdmfUnstructuredGrid(XdmfUnstructuredGrid & refGrid) :
+ XdmfGrid(refGrid)
+{
+}
+
+XdmfUnstructuredGrid::~XdmfUnstructuredGrid()
+{
+ if (mImpl) {
+ delete mImpl;
+ }
+ mImpl = NULL;
+}
+
+const std::string XdmfUnstructuredGrid::ItemTag = "Grid";
+
+void
+XdmfUnstructuredGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
+{
+ XdmfGrid::copyGrid(sourceGrid);
+ if (shared_ptr<XdmfUnstructuredGrid> classedGrid = shared_dynamic_cast<XdmfUnstructuredGrid>(sourceGrid))
+ {
+ this->setGeometry(classedGrid->getGeometry());
+ this->setTopology(classedGrid->getTopology());
+ }
+}
+
+shared_ptr<XdmfGeometry>
+XdmfUnstructuredGrid::getGeometry()
+{
+ return boost::const_pointer_cast<XdmfGeometry>
+ (static_cast<const XdmfGrid &>(*this).getGeometry());
+}
+
+std::string
+XdmfUnstructuredGrid::getItemTag() const
+{
+ return ItemTag;
+}
+
+shared_ptr<XdmfTopology>
+XdmfUnstructuredGrid::getTopology()
+{
+ return boost::const_pointer_cast<XdmfTopology>
+ (static_cast<const XdmfGrid &>(*this).getTopology());
+}
+
+void
+XdmfUnstructuredGrid::read()
+{
+ if (mGridController)
+ {
+ if (shared_ptr<XdmfUnstructuredGrid> grid = shared_dynamic_cast<XdmfUnstructuredGrid>(mGridController->read()))
+ {
+ copyGrid(grid);
+ }
+ else if (shared_dynamic_cast<XdmfGrid>(mGridController->read()))
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference");
+ }
+ }
+}
+
+void
+XdmfUnstructuredGrid::release()
+{
+ XdmfGrid::release();
+ this->setGeometry(shared_ptr<XdmfGeometry>());
+ this->setTopology(shared_ptr<XdmfTopology>());
+}
+
+void
+XdmfUnstructuredGrid::setGeometry(const shared_ptr<XdmfGeometry> geometry)
+{
+ mGeometry = geometry;
+}
+
+void
+XdmfUnstructuredGrid::setTopology(const shared_ptr<XdmfTopology> topology)
+{
+ mTopology = topology;
+}
+
+// C Wrappers
+
+XDMFUNSTRUCTUREDGRID * XdmfUnstructuredGridNew()
+{
+ try
+ {
+ shared_ptr<XdmfUnstructuredGrid> generatedGrid = XdmfUnstructuredGrid::New();
+ return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(new XdmfUnstructuredGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfUnstructuredGrid> generatedGrid = XdmfUnstructuredGrid::New();
+ return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(new XdmfUnstructuredGrid(*generatedGrid.get()))));
+ }
+}
+
+XDMFUNSTRUCTUREDGRID * XdmfUnstructuredGridNewFromRegularGrid(XDMFREGULARGRID * regularGrid, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ // Here it works when classed directly to the grid type,
+ // in other cases this may not work.
+ XdmfItem * tempPointer = (XdmfItem *)regularGrid;
+ XdmfRegularGrid * classedPointer = dynamic_cast<XdmfRegularGrid *>(tempPointer);
+ shared_ptr<XdmfRegularGrid> originGrid = shared_ptr<XdmfRegularGrid>(classedPointer, XdmfNullDeleter());
+ shared_ptr<XdmfUnstructuredGrid> generatedGrid = XdmfUnstructuredGrid::New(originGrid);
+ return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(new XdmfUnstructuredGrid(*generatedGrid.get()))));
+ }
+ catch (...)
+ {
+ // Here it works when classed directly to the grid type,
+ // in other cases this may not work.
+ XdmfItem * tempPointer = (XdmfItem *)regularGrid;
+ XdmfRegularGrid * classedPointer = dynamic_cast<XdmfRegularGrid *>(tempPointer);
+ shared_ptr<XdmfRegularGrid> originGrid = shared_ptr<XdmfRegularGrid>(classedPointer, XdmfNullDeleter());
+ shared_ptr<XdmfUnstructuredGrid> generatedGrid = XdmfUnstructuredGrid::New(originGrid);
+ return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(new XdmfUnstructuredGrid(*generatedGrid.get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFGEOMETRY * XdmfUnstructuredGridGetGeometry(XDMFUNSTRUCTUREDGRID * grid)
+{
+ XdmfItem * tempPointer = (XdmfItem *)grid;
+ XdmfUnstructuredGrid * classedPointer = dynamic_cast<XdmfUnstructuredGrid *>(tempPointer);
+ return (XDMFGEOMETRY *)((void *)(classedPointer->getGeometry().get()));
+}
+
+XDMFTOPOLOGY * XdmfUnstructuredGridGetTopology(XDMFUNSTRUCTUREDGRID * grid)
+{
+ XdmfItem * tempPointer = (XdmfItem *)grid;
+ XdmfUnstructuredGrid * classedPointer = dynamic_cast<XdmfUnstructuredGrid *>(tempPointer);
+ return (XDMFTOPOLOGY *)((void *)(classedPointer->getTopology().get()));
+}
+
+void XdmfUnstructuredGridSetGeometry(XDMFUNSTRUCTUREDGRID * grid, XDMFGEOMETRY * geometry, int passControl)
+{
+ XdmfItem * tempPointer = (XdmfItem *)grid;
+ XdmfUnstructuredGrid * classedPointer = dynamic_cast<XdmfUnstructuredGrid *>(tempPointer);
+ if (passControl) {
+ classedPointer->setGeometry(shared_ptr<XdmfGeometry>((XdmfGeometry *)geometry));
+ }
+ else {
+ classedPointer->setGeometry(shared_ptr<XdmfGeometry>((XdmfGeometry *)geometry, XdmfNullDeleter()));
+ }
+}
+
+void XdmfUnstructuredGridSetTopology(XDMFUNSTRUCTUREDGRID * grid, XDMFTOPOLOGY * topology, int passControl)
+{
+ XdmfItem * tempPointer = (XdmfItem *)grid;
+ XdmfUnstructuredGrid * classedPointer = dynamic_cast<XdmfUnstructuredGrid *>(tempPointer);
+ if (passControl) {
+ classedPointer->setTopology(shared_ptr<XdmfTopology>((XdmfTopology *)topology));
+ }
+ else {
+ classedPointer->setTopology(shared_ptr<XdmfTopology>((XdmfTopology *)topology, XdmfNullDeleter()));
+ }
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfUnstructuredGrid, XDMFUNSTRUCTUREDGRID)
+XDMF_GRID_C_CHILD_WRAPPER(XdmfUnstructuredGrid, XDMFUNSTRUCTUREDGRID)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfUnstructuredGrid.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFUNSTRUCTUREDGRID_HPP_
+#define XDMFUNSTRUCTUREDGRID_HPP_
+
+// C Compatible Includes
+#include "Xdmf.hpp"
+#include "XdmfGrid.hpp"
+#include "XdmfRegularGrid.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfRegularGrid;
+
+/**
+ * @brief An unstructured grid that consists of elements, points, and
+ * fields attached to the mesh.
+ *
+ * After creating an unstructured grid, the XdmfGeometry and
+ * XdmfTopology must be set. The XdmfTopology describes the element
+ * types contained in the grid and their connectivity. The
+ * XdmfGeometry describes the positions of nodes.
+ */
+class XDMF_EXPORT XdmfUnstructuredGrid : public XdmfGrid {
+
+public:
+
+ /**
+ * Create a new XdmfUnstructuredGrid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfUnstructuredGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleUnstructuredGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfUnstructuredGrid.
+ */
+ static shared_ptr<XdmfUnstructuredGrid> New();
+
+ /**
+ * Create a new XdmfUnstructuredGrid from a XdmfRegularGrid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfUnstructuredGrid.cpp
+ * @skipline //#initializationregular
+ * @until //#initializationregular
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleUnstructuredGrid.py
+ * @skipline #//initializationregular
+ * @until #//initializationregular
+ *
+ * @param regularGrid The grid that the unstructured grid will be created from
+ *
+ * @return Constructed XdmfUnstructuredGrid.
+ */
+ static shared_ptr<XdmfUnstructuredGrid>
+ New(const shared_ptr<XdmfRegularGrid> regularGrid);
+
+ virtual ~XdmfUnstructuredGrid();
+
+ static const std::string ItemTag;
+
+ /**
+ * Get the geometry associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfUnstructuredGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGeometry
+ * @until //#setGeometry
+ * @skipline //#getGeometry
+ * @until //#getGeometry
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleUnstructuredGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGeometry
+ * @until #//setGeometry
+ * @skipline #//getGeometry
+ * @until #//getGeometry
+ *
+ * @return The geometry associated with this grid.
+ */
+ shared_ptr<XdmfGeometry> getGeometry();
+ using XdmfGrid::getGeometry;
+
+ virtual std::string getItemTag() const;
+
+ /**
+ * Get the topology associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfUnstructuredGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setTopology
+ * @until //#setTopology
+ * @skipline //#getTopology
+ * @until //#getTopology
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleUnstructuredGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setTopology
+ * @until #//setTopology
+ * @skipline #//getTopology
+ * @until #//getTopology
+ *
+ * @return The topology associated with this grid.
+ */
+ shared_ptr<XdmfTopology> getTopology();
+ using XdmfGrid::getTopology;
+
+ virtual void read();
+
+ virtual void release();
+
+ /**
+ * Set the geometry associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfUnstructuredGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setGeometry
+ * @until //#setGeometry
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleUnstructuredGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setGeometry
+ * @until #//setGeometry
+ *
+ * @param geometry An XdmfGeometry to associate with this grid.
+ */
+ void setGeometry(const shared_ptr<XdmfGeometry> geometry);
+
+ /**
+ * Set the topology associated with this grid.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfUnstructuredGrid.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setTopology
+ * @until //#setTopology
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleUnstructuredGrid.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setTopology
+ * @until #//setTopology
+ *
+ * @param topology An XdmfTopology to associate with this grid.
+ */
+ void setTopology(const shared_ptr<XdmfTopology> topology);
+
+ XdmfUnstructuredGrid(XdmfUnstructuredGrid &);
+
+protected:
+
+ XdmfUnstructuredGrid();
+ XdmfUnstructuredGrid(const shared_ptr<XdmfRegularGrid> regularGrid);
+
+ virtual void
+ copyGrid(shared_ptr<XdmfGrid> sourceGrid);
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfUnstructuredGridImpl;
+
+ XdmfUnstructuredGrid(const XdmfUnstructuredGrid &); // Not implemented.
+ void operator=(const XdmfUnstructuredGrid &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFUNSTRUCTUREDGRID; // Simply as a typedef to ensure correct typing
+typedef struct XDMFUNSTRUCTUREDGRID XDMFUNSTRUCTUREDGRID;
+
+XDMF_EXPORT XDMFUNSTRUCTUREDGRID * XdmfUnstructuredGridNew();
+
+XDMF_EXPORT XDMFUNSTRUCTUREDGRID * XdmfUnstructuredGridNewFromRegularGrid(XDMFREGULARGRID * regularGrid, int * status);
+
+XDMF_EXPORT XDMFGEOMETRY * XdmfUnstructuredGridGetGeometry(XDMFUNSTRUCTUREDGRID * grid);
+
+XDMF_EXPORT XDMFTOPOLOGY * XdmfUnstructuredGridGetTopology(XDMFUNSTRUCTUREDGRID * grid);
+
+XDMF_EXPORT void XdmfUnstructuredGridSetGeometry(XDMFUNSTRUCTUREDGRID * grid, XDMFGEOMETRY * geometry, int passControl);
+
+XDMF_EXPORT void XdmfUnstructuredGridSetTopology(XDMFUNSTRUCTUREDGRID * grid, XDMFTOPOLOGY * topology, int passControl);
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfUnstructuredGrid, XDMFUNSTRUCTUREDGRID, XDMF)
+XDMF_GRID_C_CHILD_DECLARE(XdmfUnstructuredGrid, XDMFUNSTRUCTUREDGRID, XDMF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFUNSTRUCTUREDGRID_HPP_ */
--- /dev/null
+project(XdmfCore)
+
+include(CheckCXXSourceCompiles)
+include(SetUpVersion)
+include(TestBigEndian)
+
+if(VERSION_CONTROL_AUTOUPDATE OR
+ NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/XdmfVersion.hpp)
+ VersionCreate(
+ "Xdmf"
+ "${XDMF_MAJOR_VERSION}" "${XDMF_MINOR_VERSION}" "${XDMF_PATCH_VERSION}"
+ "XDMFCORE_EXPORT" "XdmfCore.hpp"
+ )
+endif()
+
+if(BUILD_SHARED_LIBS)
+ set(BUILD_SHARED 1)
+endif()
+
+if (FALSE) # XXX(kitware): use target-based include directories
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+endif ()
+
+if (FALSE) # XXX(kitware): VTK's module system handles dependencies
+find_package(Boost REQUIRED)
+if(Boost_FOUND)
+ include_directories(${Boost_INCLUDE_DIRS})
+endif()
+
+find_package(HDF5 REQUIRED)
+if(HDF5_FOUND)
+ include_directories(${HDF5_INCLUDE_DIRS})
+ include_directories(${HDF5_C_INCLUDE_DIR})
+ # FIXME: Would like to get this info from HDF5 so we don't have conflicting
+ # MPI versions
+ if(HDF5_IS_PARALLEL)
+ if (NOT MPI_FOUND)
+ find_package(MPI REQUIRED)
+ if(MPI_FOUND)
+ include_directories(${MPI_INCLUDE_PATH})
+ endif()
+ endif ()
+ endif()
+endif()
+
+
+find_package(LibXml2 REQUIRED)
+if(LIBXML2_FOUND)
+ include_directories(${LIBXML2_INCLUDE_DIR})
+endif()
+else ()
+vtk_module_find_package(
+ PACKAGE Boost
+ FORWARD_VERSION_REQ EXACT
+ VERSION_VAR "@Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@.@Boost_SUBMINOR_VERSION@")
+endif ()
+
+# Perform compile-time checks and generate XdmfCoreConfig.hpp
+
+TEST_BIG_ENDIAN(XDMF_BIG_ENDIAN)
+
+set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Boost_INCLUDE_DIRS})
+check_cxx_source_compiles("
+#include <boost/shared_ptr.hpp>
+
+struct Base { virtual ~Base(){} };
+struct Derived : public Base {};
+
+int main(int ac, char * av[])
+{
+ boost::shared_ptr<Base> ptr(new Base());
+ boost::shared_dynamic_cast<Derived>(ptr);
+}
+"
+HAVE_BOOST_SHARED_DYNAMIC_CAST)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XdmfCoreConfig.hpp.in
+ ${CMAKE_CURRENT_BINARY_DIR}/XdmfCoreConfig.hpp)
+
+set(XdmfCoreSources
+ XdmfArray
+ XdmfArrayReference
+ XdmfArrayType
+ XdmfBinaryController
+ XdmfCoreItemFactory
+ XdmfCoreReader
+ XdmfError
+ XdmfFunction
+ XdmfHDF5Controller
+ XdmfHDF5Writer
+ XdmfHeavyDataController
+ XdmfHeavyDataDescription
+ XdmfHeavyDataWriter
+ XdmfInformation
+ XdmfItem
+ XdmfItemProperty
+ XdmfPlaceholder
+ XdmfSparseMatrix
+ XdmfSubset
+ XdmfSystemUtils
+ ${CMAKE_CURRENT_BINARY_DIR}/XdmfVersion
+ XdmfVisitor
+ XdmfWriter)
+
+if (TIFF_FOUND)
+ set(XdmfCoreSources
+ ${XdmfCoreSources}
+ XdmfTIFFController)
+ set(FOUND_TIFF_LOCATION core/XdmfTIFFController)
+else ()
+ set(FOUND_TIFF_LOCATION "")
+endif()
+
+if (FALSE) # XXX(kitware): VTK's module system handles dependencies
+set(XdmfCoreSources
+ core/XdmfArray
+ core/XdmfArrayReference
+ core/XdmfArrayType
+ core/XdmfBinaryController
+ core/XdmfCoreItemFactory
+ core/XdmfCoreReader
+ core/XdmfError
+ core/XdmfFunction
+ core/XdmfHDF5Controller
+ core/XdmfHDF5Writer
+ core/XdmfHeavyDataController
+ core/XdmfHeavyDataDescription
+ core/XdmfHeavyDataWriter
+ core/XdmfInformation
+ core/XdmfItem
+ core/XdmfItemProperty
+ core/XdmfPlaceholder
+ core/XdmfSparseMatrix
+ core/XdmfSubset
+ core/XdmfSystemUtils
+ ${FOUND_TIFF_LOCATION}
+ ${CMAKE_CURRENT_BINARY_DIR}/XdmfVersion
+ core/XdmfVisitor
+ core/XdmfWriter
+ PARENT_SCOPE)
+endif ()
+
+if (FALSE) # XXX(kitware): use VTK's module system.
+add_library(XdmfCore ${XdmfCoreSources})
+SET_TARGET_PROPERTIES(
+ XdmfCore PROPERTIES
+ VERSION ${XDMF_VERSION}
+ SOVERSION ${XDMF_MAJOR_VERSION}
+ )
+
+target_link_libraries(XdmfCore
+ PUBLIC
+ ${HDF5_C_LIBRARIES}
+ ${LIBXML2_LIBRARIES})
+if (TIFF_FOUND)
+ target_link_libraries(XdmfCore
+ PRIVATE
+ ${TIFF_LIBRARIES})
+endif ()
+else ()
+set(sources)
+foreach (xdmf_core_source IN LISTS XdmfCoreSources)
+ list(APPEND sources
+ "${xdmf_core_source}.cpp")
+endforeach ()
+
+add_library(vtkxdmfcore ${sources})
+target_include_directories(vtkxdmfcore
+ PUBLIC
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../CMake/VersionSuite>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
+ "$<INSTALL_INTERFACE:${_vtk_build_HEADERS_DESTINATION}/vtkxdmf3/core>")
+target_link_libraries(vtkxdmfcore
+ PUBLIC
+ VTK::libxml2
+ Boost::boost
+ PRIVATE
+ VTK::hdf5)
+_vtk_module_apply_properties(vtkxdmfcore)
+_vtk_module_install(vtkxdmfcore)
+endif ()
+
+if(WIN32)
+ #add_definitions(-D_HDF5USEDLL_ -D_HDF5USEHLDLL_)
+ if (BUILD_SHARED_LIBS)
+ # XXX(kitware): mangle the library name.
+ set_target_properties(vtkxdmfcore PROPERTIES
+ DEFINE_SYMBOL XdmfCore_EXPORTS)
+ endif()
+endif()
+
+if(XDMF_WRAP_JAVA)
+ XDMF_SWIG_JAVA(XdmfCore)
+endif()
+
+if(XDMF_WRAP_PYTHON)
+ if (NOT BUILD_SHARED_LIBS)
+ message(FATAL_ERROR "Python Wrappers do not function"
+ " properly without shared libraries")
+ endif (NOT BUILD_SHARED_LIBS)
+ XDMF_SWIG_PYTHON(XdmfCore)
+endif()
+
+file(GLOB_RECURSE
+ XdmfCoreHeaders
+ "*.hpp" "*.tpp" "*.i"
+ "../CMake/VersionSuite/*.hpp")
+file(GLOB LokiHeaders loki/*.h)
+
+set(XdmfCoreHeaders
+ ${XdmfCoreHeaders}
+ ${CMAKE_CURRENT_BINARY_DIR}/XdmfCoreConfig.hpp)
+if (FALSE)
+install(FILES ${XdmfCoreHeaders} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(FILES ${LokiHeaders} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/loki)
+install(TARGETS XdmfCore
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+else ()
+vtk_module_install_headers(
+ FILES ${XdmfCoreHeaders}
+ SUBDIR "vtkxdmf3/core")
+vtk_module_install_headers(
+ FILES ${LokiHeaders}
+ SUBDIR "vtkxdmf3/core/loki")
+endif ()
+
+if (Boost_FOUND)
+ set(FOUND_BOOST_INCLUDES ${Boost_INCLUDE_DIRS})
+else ()
+ set(FOUND_BOOST_INCLUDES "")
+endif ()
+set(XdmfCore_INCLUDE_DIRS
+ ${FOUND_BOOST_INCLUDES}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${HDF5_INCLUDE_DIR}
+ ${LIBXML2_INCLUDE_DIR}
+ ${PYTHON_INCLUDE_DIRS}
+ CACHE INTERNAL "")
+
+set(XDMF_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include PARENT_SCOPE)
+set(XDMF_DIR ${CMAKE_INSTALL_PREFIX} PARENT_SCOPE)
+
+if(XDMF_BUILD_DSM)
+ add_subdirectory(dsm)
+ set(XDMF_DSM_IS_CRAY "${XDMF_DSM_IS_CRAY}" PARENT_SCOPE)
+endif(XDMF_BUILD_DSM)
+
+if(XDMF_BUILD_TESTING)
+ add_subdirectory(tests)
+endif()
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfArray.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <boost/tokenizer.hpp>
+#include <limits>
+#include <sstream>
+#include <utility>
+#include <stack>
+#include <math.h>
+#include <string.h>
+#include <cstdint>
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfArrayReference.hpp"
+#include "XdmfBinaryController.hpp"
+#include "XdmfCoreReader.hpp"
+#include "XdmfFunction.hpp"
+#include "XdmfSubset.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfVisitor.hpp"
+#include "XdmfError.hpp"
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfArray,
+ XdmfHeavyDataController,
+ HeavyDataController,
+ Name)
+
+class XdmfArray::Clear : public boost::static_visitor<void> {
+public:
+
+ Clear(XdmfArray * const array) :
+ mArray(array)
+ {
+ }
+
+ void
+ operator()(const boost::blank & array) const
+ {
+ return;
+ }
+
+ template<typename T>
+ void
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ array->clear();
+ }
+
+ template<typename T>
+ void
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+ XdmfArray * const mArray;
+};
+
+class XdmfArray::Erase : public boost::static_visitor<void> {
+public:
+
+ Erase(XdmfArray * const array,
+ const unsigned int index) :
+ mArray(array),
+ mIndex(index)
+ {
+ }
+
+ void
+ operator()(const boost::blank & array) const
+ {
+ return;
+ }
+
+ template<typename T>
+ void
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ array->erase(array->begin() + mIndex);
+ }
+
+ template<typename T>
+ void
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * const mArray;
+ const unsigned int mIndex;
+};
+
+class XdmfArray::GetArrayType :
+ public boost::static_visitor<shared_ptr<const XdmfArrayType> > {
+public:
+
+ GetArrayType(const shared_ptr<XdmfHeavyDataController> & heavyDataController) :
+ mHeavyDataController(heavyDataController)
+ {
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const char * const) const
+ {
+ return XdmfArrayType::Int8();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const short * const) const
+ {
+ return XdmfArrayType::Int16();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const int * const) const
+ {
+ return XdmfArrayType::Int32();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const long * const) const
+ {
+ return XdmfArrayType::Int64();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const float * const) const
+ {
+ return XdmfArrayType::Float32();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const double * const) const
+ {
+ return XdmfArrayType::Float64();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const unsigned char * const) const
+ {
+ return XdmfArrayType::UInt8();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const unsigned short * const) const
+ {
+ return XdmfArrayType::UInt16();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const unsigned int * const) const
+ {
+ return XdmfArrayType::UInt32();
+ }
+
+#if defined(_WIN32) || defined(__APPLE__)
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const unsigned long * const) const
+ {
+ return XdmfArrayType::UInt64();
+ }
+#endif
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const uint64_t * const) const
+ {
+ return XdmfArrayType::UInt64();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const std::string * const) const
+ {
+ return XdmfArrayType::String();
+ }
+
+ shared_ptr<const XdmfArrayType>
+ operator()(const boost::blank & array) const
+ {
+ if(mHeavyDataController) {
+ return mHeavyDataController->getType();
+ }
+ return XdmfArrayType::Uninitialized();
+ }
+
+ template<typename T>
+ shared_ptr<const XdmfArrayType>
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ return this->getArrayType(&(array.get()->operator[](0)));
+ }
+
+ template<typename T>
+ shared_ptr<const XdmfArrayType>
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ return this->getArrayType(array.get());
+ }
+
+private:
+
+ const shared_ptr<XdmfHeavyDataController> mHeavyDataController;
+};
+
+class XdmfArray::GetCapacity : public boost::static_visitor<unsigned int> {
+public:
+
+ GetCapacity()
+ {
+ }
+
+ unsigned int
+ operator()(const boost::blank & array) const
+ {
+ return 0;
+ }
+
+ template<typename T>
+ unsigned int
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ return array->capacity();
+ }
+
+ template<typename T>
+ unsigned int
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ return 0;
+ }
+};
+
+class XdmfArray::GetValuesPointer :
+ public boost::static_visitor<const void *> {
+public:
+
+ GetValuesPointer()
+ {
+ }
+
+ const void *
+ operator()(const boost::blank & array) const
+ {
+ return NULL;
+ }
+
+ template<typename T>
+ const void *
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ return &array->operator[](0);
+ }
+
+ template<typename T>
+ const void *
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ return array.get();
+ }
+};
+
+class XdmfArray::GetValuesString : public boost::static_visitor<std::string> {
+public:
+
+ GetValuesString(const int arrayPointerNumValues) :
+ mArrayPointerNumValues(arrayPointerNumValues)
+ {
+ }
+
+ template<typename T, typename U>
+ std::string
+ getValuesString(const T * const array,
+ const int numValues) const
+ {
+ const int lastIndex = numValues - 1;
+
+ if(lastIndex < 0) {
+ return "";
+ }
+
+ std::stringstream toReturn;
+ toReturn.precision(std::numeric_limits<U>::digits10 + 2);
+ for(int i=0; i<lastIndex; ++i) {
+ toReturn << (U)array[i] << " ";
+ }
+ toReturn << (U)array[lastIndex];
+ return toReturn.str();
+ }
+
+ std::string
+ getValuesString(const char * const array,
+ const int numValues) const
+ {
+ return getValuesString<char, int>(array, numValues);
+ }
+
+ std::string
+ getValuesString(const unsigned char * const array,
+ const int numValues) const
+ {
+ return getValuesString<unsigned char, int>(array, numValues);
+ }
+
+ template<typename T>
+ std::string
+ getValuesString(const T * const array,
+ const int numValues) const
+ {
+ return getValuesString<T, T>(array, numValues);
+ }
+
+ std::string
+ operator()(const boost::blank & array) const
+ {
+ return "";
+ }
+
+ template<typename T>
+ std::string
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ return getValuesString(&(array->operator[](0)), array->size());
+ }
+
+ template<typename T>
+ std::string
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ return getValuesString(array.get(), mArrayPointerNumValues);
+ }
+
+private:
+
+ const unsigned int mArrayPointerNumValues;
+};
+
+class XdmfArray::InsertArray : public boost::static_visitor<void> {
+public:
+
+ InsertArray(XdmfArray * const array,
+ const unsigned int startIndex,
+ const unsigned int valuesStartIndex,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride,
+ std::vector<unsigned int> & dimensions,
+ const shared_ptr<const XdmfArray> & arrayToCopy) :
+ mArray(array),
+ mStartIndex(startIndex),
+ mValuesStartIndex(valuesStartIndex),
+ mNumValues(numValues),
+ mArrayStride(arrayStride),
+ mValuesStride(valuesStride),
+ mDimensions(dimensions),
+ mArrayToCopy(arrayToCopy)
+ {
+ }
+
+ void
+ operator()(const boost::blank & array) const
+ {
+ const shared_ptr<const XdmfArrayType> copyType =
+ mArrayToCopy->getArrayType();
+ if(copyType == XdmfArrayType::Uninitialized()) {
+ return;
+ }
+ mArray->initialize(copyType);
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ template<typename T>
+ void
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
+ if(array->size() < size) {
+ array->resize(size);
+ mDimensions.clear();
+ }
+ mArrayToCopy->getValues(mValuesStartIndex,
+ &(array->operator[](mStartIndex)),
+ mNumValues,
+ mValuesStride,
+ mArrayStride);
+ }
+
+ template<typename T>
+ void
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * const mArray;
+ const unsigned int mStartIndex;
+ const unsigned int mValuesStartIndex;
+ const unsigned int mNumValues;
+ const unsigned int mArrayStride;
+ const unsigned int mValuesStride;
+ std::vector<unsigned int> & mDimensions;
+ const shared_ptr<const XdmfArray> mArrayToCopy;
+};
+
+class XdmfArray::InternalizeArrayPointer : public boost::static_visitor<void> {
+public:
+
+ InternalizeArrayPointer(XdmfArray * const array) :
+ mArray(array)
+ {
+ }
+
+ void
+ operator()(const boost::blank & array) const
+ {
+ return;
+ }
+
+ template<typename T>
+ void
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ return;
+ }
+
+ template<typename T>
+ void
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ const T * const pointer = array.get();
+ shared_ptr<std::vector<T> > newArray(new std::vector<T>(pointer,
+ pointer + mArray->mArrayPointerNumValues));
+ mArray->mArray = newArray;
+ mArray->mArrayPointerNumValues = 0;
+ }
+
+private:
+
+ XdmfArray * const mArray;
+};
+
+class XdmfArray::IsInitialized : public boost::static_visitor<bool> {
+public:
+
+ IsInitialized()
+ {
+ }
+
+ bool
+ operator()(const boost::blank &) const
+ {
+ return false;
+ }
+
+ template<typename T>
+ bool
+ operator()(const shared_ptr<std::vector<T> > &) const
+ {
+ return true;
+ }
+
+ template<typename T>
+ bool
+ operator()(const T &) const
+ {
+ return true;
+ }
+};
+
+class XdmfArray::Reserve : public boost::static_visitor<void> {
+public:
+
+ Reserve(XdmfArray * const array,
+ const unsigned int size):
+ mArray(array),
+ mSize(size)
+ {
+ }
+
+ void
+ operator()(const boost::blank & array) const
+ {
+ mArray->mTmpReserveSize = mSize;
+ }
+
+ template<typename T>
+ void
+ operator()(shared_ptr<std::vector<T> > & array) const
+ {
+ array->reserve(mSize);
+ }
+
+ template<typename T>
+ void
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * const mArray;
+ const unsigned int mSize;
+};
+
+class XdmfArray::Size : public boost::static_visitor<unsigned int> {
+public:
+
+ Size(const XdmfArray * const array) :
+ mArray(array)
+ {
+ }
+
+ unsigned int
+ operator()(const boost::blank & array) const
+ {
+ unsigned int total = 0;
+ for (unsigned int i = 0; i < mArray->mHeavyDataControllers.size(); ++i) {
+ total += mArray->mHeavyDataControllers[i]->getSize();
+ }
+ return total;
+ }
+
+ template<typename T>
+ unsigned int
+ operator()(const shared_ptr<std::vector<T> > & array) const
+ {
+ return array->size();
+ }
+
+ template<typename T>
+ unsigned int
+ operator()(const boost::shared_array<const T> & array) const
+ {
+ return mArray->mArrayPointerNumValues;
+ }
+
+private:
+
+ const XdmfArray * const mArray;
+};
+
+shared_ptr<XdmfArray>
+XdmfArray::New()
+{
+ shared_ptr<XdmfArray> p(new XdmfArray());
+ return p;
+}
+
+XdmfArray::XdmfArray() :
+ mArrayPointerNumValues(0),
+ mName(""),
+ mTmpReserveSize(0),
+ mReadMode(XdmfArray::Controller)
+{
+}
+
+XdmfArray::XdmfArray(XdmfArray & refArray):
+ XdmfItem(refArray),
+ mDimensions(refArray.getDimensions()),
+ mName(refArray.getName()),
+ mReadMode(refArray.getReadMode())
+{
+ if (refArray.getArrayType() != XdmfArrayType::Uninitialized()) {
+ this->initialize(refArray.getArrayType(), 0);
+ if (refArray.getSize() > 0) {
+ shared_ptr<const XdmfArray> tempPointer = shared_ptr<const XdmfArray>(&refArray, XdmfNullDeleter());
+ this->insert(0, tempPointer, 0, tempPointer->getSize());
+ }
+ }
+ if (refArray.getNumberHeavyDataControllers() > 0) {
+ for (unsigned int i = 0; i < refArray.getNumberHeavyDataControllers(); ++i) {
+ this->insert(refArray.getHeavyDataController(i));
+ }
+ }
+ if (refArray.mReference) {
+ this->setReference(refArray.getReference());
+ }
+}
+
+XdmfArray::~XdmfArray()
+{
+}
+
+const std::string XdmfArray::ItemTag = "DataItem";
+
+void
+XdmfArray::clear()
+{
+ boost::apply_visitor(Clear(this),
+ mArray);
+ mDimensions.clear();
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::erase(const unsigned int index)
+{
+ boost::apply_visitor(Erase(this,
+ index),
+ mArray);
+ mDimensions.clear();
+ this->setIsChanged(true);
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArray::getArrayType() const
+{
+ if (mHeavyDataControllers.size()>0) {
+ return boost::apply_visitor(GetArrayType(mHeavyDataControllers[0]),
+ mArray);
+ }
+ else {
+ return boost::apply_visitor(GetArrayType(shared_ptr<XdmfHeavyDataController>()),
+ mArray);
+ }
+}
+
+unsigned int
+XdmfArray::getCapacity() const
+{
+ return boost::apply_visitor(GetCapacity(),
+ mArray);
+}
+
+std::vector<unsigned int>
+XdmfArray::getDimensions() const
+{
+ if(mDimensions.size() == 0) {
+ if(!this->isInitialized() && mHeavyDataControllers.size() > 0) {
+ std::vector<unsigned int> returnDimensions;
+ std::vector<unsigned int> tempDimensions;
+ // Find the controller with the most dimensions
+ int dimControllerIndex = 0;
+ unsigned int dimSizeMax = 0;
+ unsigned int dimTotal = 0;
+ for (unsigned int i = 0; i < mHeavyDataControllers.size(); ++i) {
+ dimTotal += mHeavyDataControllers[i]->getSize();
+ if (mHeavyDataControllers[i]->getSize() > dimSizeMax) {
+ dimSizeMax = mHeavyDataControllers[i]->getSize();
+ dimControllerIndex = i;
+ }
+ }
+ // Total up the size of the lower dimensions
+ int controllerDimensionSubtotal = 1;
+ for (unsigned int i = 0;
+ i < mHeavyDataControllers[dimControllerIndex]->getDimensions().size() - 1;
+ ++i) {
+ returnDimensions.push_back(mHeavyDataControllers[dimControllerIndex]->getDimensions()[i]);
+ controllerDimensionSubtotal *= mHeavyDataControllers[dimControllerIndex]->getDimensions()[i];
+ }
+ // Divide the total contained by the dimensions by the size of the lower dimensions
+ returnDimensions.push_back(dimTotal/controllerDimensionSubtotal);
+ return returnDimensions;
+ }
+ const unsigned int size = this->getSize();
+ return std::vector<unsigned int>(1, size);
+ }
+ return mDimensions;
+}
+
+std::string
+XdmfArray::getDimensionsString() const
+{
+ const std::vector<unsigned int> dimensions = this->getDimensions();
+ return GetValuesString(dimensions.size()).getValuesString(&dimensions[0],
+ dimensions.size());
+}
+
+std::map<std::string, std::string>
+XdmfArray::getItemProperties() const
+{
+ std::map<std::string, std::string> arrayProperties;
+ if(mHeavyDataControllers.size() > 0) {
+ mHeavyDataControllers[0]->getProperties(arrayProperties);
+ }
+ else {
+ arrayProperties.insert(std::make_pair("Format", "XML"));
+ }
+ arrayProperties.insert(std::make_pair("Dimensions",
+ this->getDimensionsString()));
+ if(mName.compare("") != 0) {
+ arrayProperties.insert(std::make_pair("Name", mName));
+ }
+ shared_ptr<const XdmfArrayType> type = this->getArrayType();
+ type->getProperties(arrayProperties);
+ return arrayProperties;
+}
+
+std::string
+XdmfArray::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::string
+XdmfArray::getName() const
+{
+ return mName;
+}
+
+XdmfArray::ReadMode
+XdmfArray::getReadMode() const
+{
+ return mReadMode;
+}
+
+unsigned int
+XdmfArray::getSize() const
+{
+ return boost::apply_visitor(Size(this),
+ mArray);
+}
+
+shared_ptr<XdmfArrayReference>
+XdmfArray::getReference()
+{
+ if (mReference) {
+ return mReference;
+ }
+ else {
+ // Returning arbitrary Reference since one isn't defined
+ return shared_ptr<XdmfArrayReference>();
+ }
+}
+
+void *
+XdmfArray::getValuesInternal()
+{
+ return const_cast<void *>
+ (static_cast<const XdmfArray &>(*this).getValuesInternal());
+}
+
+const void *
+XdmfArray::getValuesInternal() const
+{
+ return boost::apply_visitor(GetValuesPointer(),
+ mArray);
+}
+
+std::string
+XdmfArray::getValuesString() const
+{
+ return boost::apply_visitor(GetValuesString(mArrayPointerNumValues),
+ mArray);
+}
+
+shared_ptr<XdmfHeavyDataController>
+XdmfArray::getHeavyDataController()
+{
+ return boost::const_pointer_cast<XdmfHeavyDataController>
+ (static_cast<const XdmfArray &>(*this).getHeavyDataController(0));
+}
+
+shared_ptr<const XdmfHeavyDataController>
+XdmfArray::getHeavyDataController() const
+{
+ if (mHeavyDataControllers.size() > 0) {
+ return mHeavyDataControllers[0];
+ }
+ else {
+ return shared_ptr<XdmfHeavyDataController>();
+ }
+}
+
+void
+XdmfArray::initialize(const shared_ptr<const XdmfArrayType> & arrayType,
+ const unsigned int size)
+{
+ if(arrayType == XdmfArrayType::Int8()) {
+ this->initialize<char>(size);
+ }
+ else if(arrayType == XdmfArrayType::Int16()) {
+ this->initialize<short>(size);
+ }
+ else if(arrayType == XdmfArrayType::Int32()) {
+ this->initialize<int>(size);
+ }
+ else if(arrayType == XdmfArrayType::Int64()) {
+ this->initialize<long>(size);
+ }
+ else if(arrayType == XdmfArrayType::Float32()) {
+ this->initialize<float>(size);
+ }
+ else if(arrayType == XdmfArrayType::Float64()) {
+ this->initialize<double>(size);
+ }
+ else if(arrayType == XdmfArrayType::UInt8()) {
+ this->initialize<unsigned char>(size);
+ }
+ else if(arrayType == XdmfArrayType::UInt16()) {
+ this->initialize<unsigned short>(size);
+ }
+ else if(arrayType == XdmfArrayType::UInt32()) {
+ this->initialize<unsigned int>(size);
+ }
+ else if(arrayType == XdmfArrayType::UInt64()) {
+ this->initialize<uint64_t>(size);
+ }
+ else if(arrayType == XdmfArrayType::String()) {
+ this->initialize<std::string>(size);
+ }
+ else if(arrayType == XdmfArrayType::Uninitialized()) {
+ this->release();
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Array of unsupported type in XdmfArray::initialize");
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::initialize(const shared_ptr<const XdmfArrayType> & arrayType,
+ const std::vector<unsigned int> & dimensions)
+{
+ mDimensions = dimensions;
+ const unsigned int size = std::accumulate(dimensions.begin(),
+ dimensions.end(),
+ 1,
+ std::multiplies<unsigned int>());
+ return this->initialize(arrayType, size);
+}
+
+void
+XdmfArray::insert(const unsigned int startIndex,
+ const shared_ptr<const XdmfArray> values,
+ const unsigned int valuesStartIndex,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride)
+{
+ boost::apply_visitor(InsertArray(this,
+ startIndex,
+ valuesStartIndex,
+ numValues,
+ arrayStride,
+ valuesStride,
+ mDimensions,
+ values),
+ mArray);
+ this->setIsChanged(true);
+}
+
+
+void
+XdmfArray::insert(const std::vector<unsigned int> startIndex,
+ const shared_ptr<const XdmfArray> values,
+ const std::vector<unsigned int> valuesStartIndex,
+ const std::vector<unsigned int> numValues,
+ const std::vector<unsigned int> numInserted,
+ const std::vector<unsigned int> arrayStride,
+ const std::vector<unsigned int> valuesStride)
+{
+ // Ensuring dimensions match up when pulling data
+ if ((values->getDimensions().size() == valuesStartIndex.size()
+ && valuesStartIndex.size() == numValues.size()
+ && numValues.size() == valuesStride.size())
+ && (numInserted.size() == startIndex.size()
+ && startIndex.size() == this->getDimensions().size()
+ && this->getDimensions().size() == arrayStride.size())) {
+ // Pull data from values
+ std::vector<unsigned int > dimTotalVector;
+ unsigned int dimTotal = 1;
+ for (unsigned int i = 0; i < values->getDimensions().size(); ++i) {
+ dimTotalVector.push_back(dimTotal);
+ dimTotal *= values->getDimensions()[i];
+ }
+ std::vector<unsigned int> indexVector;
+ for (unsigned int i = 0; i < values->getDimensions().size(); ++i) {
+ indexVector.push_back(0);
+ }
+ shared_ptr<XdmfArray> holderArray = XdmfArray::New();
+ unsigned int holderoffset = 0;
+ // End when the last index is incremented
+ while (indexVector[indexVector.size()-1] < 1) {
+ // Initialize the section of the array you're pulling from
+ unsigned int startTotal = 0;
+ dimTotal = 1;
+ for (unsigned int i = 0; i < values->getDimensions().size(); ++i) {
+ // Stride doesn't factor in to the first dimension
+ // Since it's being used with the insert call
+ if (i == 0) {
+ startTotal += valuesStartIndex[i] * dimTotal;
+ }
+ else {
+ startTotal += valuesStartIndex[i] * dimTotal
+ + valuesStride[i] * dimTotal * indexVector[i-1];
+ }
+ dimTotal *= values->getDimensions()[i];
+ }
+ // Insert the subsection
+ holderArray->insert(holderoffset,
+ values,
+ startTotal,
+ numValues[0],
+ 1,
+ valuesStride[0]);
+ holderoffset+=numValues[0];
+ // Increment up the vector
+ bool increment = true;
+ for (unsigned int i = 0; i < indexVector.size() && increment; ++i) {
+ indexVector[i]++;
+ // To keep the loop from breaking at the end
+ if (i+1 < numValues.size()) {
+ if (indexVector[i] >= numValues[i+1]) {
+ indexVector[i] = indexVector[i] % numValues[i+1];
+ }
+ else {
+ increment = false;
+ }
+ }
+ }
+ }
+ // Values being inserted retrieved
+ // Use an variation of the last loop to insert into this array
+
+ indexVector.clear();
+ for (unsigned int i = 0; i < this->getDimensions().size(); ++i) {
+ indexVector.push_back(0);
+ }
+ holderoffset = 0;
+ // End when the last index is incremented
+ while (indexVector[indexVector.size()-1] < 1) {
+ // Initialize the section of the array you're pulling from
+ unsigned int startTotal = 0;
+ dimTotal = 1;
+ for (unsigned int i = 0; i < this->getDimensions().size(); ++i) {
+ if (i == 0) {
+ // Stride doesn't factor in to the first dimension
+ // Since it's being used with the insert call
+ startTotal += startIndex[i] * dimTotal;
+ }
+ else {
+ startTotal += startIndex[i] * dimTotal + arrayStride[i] * dimTotal * indexVector[i-1];
+ }
+ dimTotal *= this->getDimensions()[i];
+ }
+ // Insert the subsection
+ this->insert(startTotal, holderArray, holderoffset, numInserted[0], arrayStride[0], 1);
+ holderoffset+=numInserted[0];
+ // Increment up the vector
+ bool increment = true;
+ for (unsigned int i = 0; i < indexVector.size() && increment; ++i) {
+ indexVector[i]++;
+ if (i+1 < numInserted.size()) {
+ // To keep the loop from breaking at the end
+ if (indexVector[i] >= numInserted[i+1]) {
+ indexVector[i] = indexVector[i] % numInserted[i+1];
+ }
+ else {
+ increment = false;
+ }
+ }
+ }
+ }
+ this->setIsChanged(true);
+ }
+ else {
+ // Throw an error
+ if (!(values->getDimensions().size() == valuesStartIndex.size()
+ && valuesStartIndex.size() == numValues.size()
+ && numValues.size() == valuesStride.size())) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Number of starts, strides, and/or values "
+ "retrieved does not match up with the dimensions "
+ "of the array being retrieved from");
+ }
+ else if (!(numInserted.size() == startIndex.size()
+ && startIndex.size() == this->getDimensions().size()
+ && this->getDimensions().size() == arrayStride.size())) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Number of starts, strides, and/or values "
+ "written does not match up with the dimensions "
+ "of the array being inserted into");
+ }
+ }
+}
+
+bool
+XdmfArray::isInitialized() const
+{
+ return boost::apply_visitor(IsInitialized(),
+ mArray);
+}
+
+void
+XdmfArray::internalizeArrayPointer()
+{
+ boost::apply_visitor(InternalizeArrayPointer(this),
+ mArray);
+}
+
+void
+XdmfArray::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ // This inserts any XdmfInformation in childItems into the object.
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+
+ bool filled = false;
+
+ // Check for Function
+ std::map<std::string, std::string>::const_iterator itemType =
+ itemProperties.find("ItemType");
+
+ if (itemType != itemProperties.end()) {
+ if (itemType->second.compare("Function") == 0) {
+ std::map<std::string, std::string>::const_iterator expressionLocation =
+ itemProperties.find("Function");
+ if (expressionLocation == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Function' not found in itemProperties for Function"
+ " ItemType in XdmfArray::populateItem");
+ }
+ std::string expression = expressionLocation->second;
+
+ // Convert from old format to new Variable format
+ // $X -> ValX
+ size_t loc = expression.find("$");
+
+ while (loc != std::string::npos) {
+ expression.replace(loc, 1, "Val");
+ loc = expression.find("$", loc);
+ }
+
+ // Create Variable list
+
+ std::map<std::string, shared_ptr<XdmfArray> > variableMap;
+
+ unsigned int variableIndex = 0;
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ std::stringstream variableKey;
+ variableKey << "Val" << variableIndex;
+ variableMap[variableKey.str()] = array;
+ variableIndex++;
+ }
+ }
+
+ shared_ptr<XdmfFunction> function = XdmfFunction::New(expression, variableMap);
+
+ this->setReference(function);
+ this->setReadMode(XdmfArray::Reference);
+ filled = true;
+ }
+ else if (itemType->second.compare("HyperSlab") == 0) {
+
+ shared_ptr<XdmfArray> dimArray;
+ shared_ptr<XdmfArray> valArray;
+
+ unsigned int foundArrayIndex = 0;
+
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ if (foundArrayIndex == 0)
+ {
+ dimArray = array;
+ foundArrayIndex++;
+ }
+ else if (foundArrayIndex == 1)
+ {
+ valArray = array;
+ foundArrayIndex++;
+ }
+ }
+ }
+
+ if (!(dimArray))
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Hyperslab description missing");
+ }
+ if (!(valArray))
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Hyperslab values missing");
+ }
+
+ if (dimArray->getSize() % 3 != 0)
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Hyperslab description structured improperly");
+ }
+
+ // A start, stride, and dimension need to be
+ // specified for each dimension
+ unsigned int numDims = dimArray->getSize() / 3;
+
+ // Start, stride, and dims are set via the first array provided
+ std::vector<unsigned int> start;
+ std::vector<unsigned int> stride;
+ std::vector<unsigned int> dimensions;
+
+ unsigned int i = 0;
+
+ while (i < dimArray->getSize() / 3)
+ {
+ start.push_back(dimArray->getValue<unsigned int>(i));
+ ++i;
+ }
+
+ while (i < 2 * (dimArray->getSize() / 3))
+ {
+ stride.push_back(dimArray->getValue<unsigned int>(i));
+ ++i;
+ }
+
+ while (i < dimArray->getSize())
+ {
+ dimensions.push_back(dimArray->getValue<unsigned int>(i));
+ ++i;
+ }
+
+ shared_ptr<XdmfSubset> subset =
+ XdmfSubset::New(valArray,
+ start,
+ stride,
+ dimensions);
+ this->setReference(subset);
+ this->setReadMode(XdmfArray::Reference);
+ filled = true;
+ }
+ }
+
+ if (!filled) {
+ std::vector<shared_ptr<XdmfHeavyDataController> > readControllers = reader->generateHeavyDataControllers(itemProperties);
+
+ mHeavyDataControllers.clear();
+
+ for (unsigned int i = 0; i < readControllers.size(); ++i) {
+ mHeavyDataControllers.push_back(readControllers[i]);
+ }
+
+ const shared_ptr<const XdmfArrayType> arrayType =
+ XdmfArrayType::New(itemProperties);
+
+ std::map<std::string, std::string>::const_iterator content =
+ itemProperties.find("Content");
+ if(content == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Content' not found in itemProperties in "
+ "XdmfArray::populateItem");
+ }
+
+ unsigned int contentIndex;
+
+ const std::string & contentVal = content->second;
+
+ std::vector<std::string> contentVals;
+
+ // Split the content based on "|" characters
+ size_t barSplit = 0;
+ std::string splitString(contentVal);
+ std::string subcontent;
+ while (barSplit != std::string::npos) {
+ barSplit = 0;
+ barSplit = splitString.find_first_of("|", barSplit);
+ if (barSplit == std::string::npos) {
+ subcontent = splitString;
+ }
+ else {
+ subcontent = splitString.substr(0, barSplit);
+ splitString = splitString.substr(barSplit+1);
+ barSplit++;
+ }
+ contentVals.push_back(subcontent);
+ }
+
+ std::map<std::string, std::string>::const_iterator dimensions =
+ itemProperties.find("Dimensions");
+ if(dimensions == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Dimensions' not found in itemProperties in "
+ "XdmfArray::populateItem");
+ }
+
+ boost::tokenizer<> tokens(dimensions->second);
+ for(boost::tokenizer<>::const_iterator iter = tokens.begin();
+ iter != tokens.end();
+ ++iter) {
+ mDimensions.push_back(atoi((*iter).c_str()));
+ }
+
+ std::map<std::string, std::string>::const_iterator format =
+ itemProperties.find("Format");
+ if(format == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Format' not found in itemProperties in "
+ "XdmfArray::populateItem");
+ }
+ const std::string & formatVal = format->second;
+
+ if (readControllers.size() == 0) {
+ if(formatVal.compare("XML") == 0) {
+ this->initialize(arrayType,
+ mDimensions);
+ unsigned int index = 0;
+ boost::char_separator<char> sep(" \t\n");
+ for (contentIndex = 0; contentIndex < contentVals.size(); ++contentIndex)
+ {
+ boost::tokenizer<boost::char_separator<char> > tokens(contentVals[contentIndex], sep);
+ if(arrayType == XdmfArrayType::String()) {
+ for(boost::tokenizer<boost::char_separator<char> >::const_iterator
+ iter = tokens.begin();
+ iter != tokens.end();
+ ++iter, ++index) {
+ this->insert(index, *iter);
+ }
+ }
+ else {
+ for(boost::tokenizer<boost::char_separator<char> >::const_iterator
+ iter = tokens.begin();
+ iter != tokens.end();
+ ++iter, ++index) {
+ this->insert(index, atof((*iter).c_str()));
+ }
+ }
+ }
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Data Format "
+ "in XdmfArray::populateItem");
+ }
+ }
+ }
+
+ std::map<std::string, std::string>::const_iterator name =
+ itemProperties.find("Name");
+ if(name != itemProperties.end()) {
+ mName = name->second;
+ }
+ else {
+ mName = "";
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::read()
+{
+ switch (mReadMode)
+ {
+ case XdmfArray::Controller:
+ this->readController();
+ break;
+ case XdmfArray::Reference:
+ this->readReference();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Read Mode");
+ }
+}
+
+void
+XdmfArray::readController()
+{
+ if(mHeavyDataControllers.size() > 1) {
+ this->release();
+ for (unsigned int i = 0; i < mHeavyDataControllers.size(); ++i) {
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ mHeavyDataControllers[i]->read(tempArray.get());
+ unsigned int dimTotal = 1;
+ for (unsigned int j = 0; j < mHeavyDataControllers[i]->getDimensions().size(); ++j) {
+ dimTotal *= mHeavyDataControllers[i]->getDimensions()[j];
+ }
+ this->insert(mHeavyDataControllers[i]->getArrayOffset(), tempArray, 0, dimTotal, 1, 1);
+ }
+ std::vector<unsigned int> returnDimensions;
+ std::vector<unsigned int> tempDimensions;
+ // Find the controller with the most dimensions
+ int dimControllerIndex = 0;
+ unsigned int dimSizeMax = 0;
+ unsigned int dimTotal = 0;
+ for (unsigned int i = 0; i < mHeavyDataControllers.size(); ++i) {
+ dimTotal += mHeavyDataControllers[i]->getSize();
+ if (mHeavyDataControllers[i]->getSize() > dimSizeMax) {
+ dimSizeMax = mHeavyDataControllers[i]->getSize();
+ dimControllerIndex = i;
+ }
+ }
+ // Total up the size of the lower dimensions
+ int controllerDimensionSubtotal = 1;
+ for (unsigned int i = 0;
+ i < mHeavyDataControllers[dimControllerIndex]->getDimensions().size() - 1;
+ ++i) {
+ returnDimensions.push_back(mHeavyDataControllers[dimControllerIndex]->getDimensions()[i]);
+ controllerDimensionSubtotal *= mHeavyDataControllers[dimControllerIndex]->getDimensions()[i];
+ }
+ // Divide the total contained by the dimensions by the size of the lower dimensions
+ returnDimensions.push_back(dimTotal/controllerDimensionSubtotal);
+ mDimensions = returnDimensions;
+ }
+ else if (mHeavyDataControllers.size() == 1 && mHeavyDataControllers[0]->getArrayOffset() == 0) {
+ this->release();
+ mHeavyDataControllers[0]->read(this);
+ mDimensions = mHeavyDataControllers[0]->getDimensions();
+ }
+ else if (mHeavyDataControllers.size() == 1 && mHeavyDataControllers[0]->getArrayOffset() > 0) {
+ this->release();
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ mHeavyDataControllers[0]->read(tempArray.get());
+ this->insert(mHeavyDataControllers[0]->getArrayOffset(), tempArray, 0, mHeavyDataControllers[0]->getSize(), 1, 1);
+ mDimensions = mHeavyDataControllers[0]->getDimensions();
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::readReference()
+{
+ shared_ptr<XdmfArray> tempArray = mReference->read();
+ this->swap(tempArray);
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::release()
+{
+ mArray = boost::blank();
+ mArrayPointerNumValues = 0;
+ mDimensions.clear();
+}
+
+void
+XdmfArray::reserve(const unsigned int size)
+{
+ boost::apply_visitor(Reserve(this,
+ size),
+ mArray);
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::setHeavyDataController(shared_ptr<XdmfHeavyDataController> newController)
+{
+ // Since this is replacing the previous version which was designed to
+ // completely replace the controller of the array
+ // It will clear the current controllers before adding the new one in
+ mHeavyDataControllers.clear();
+ mHeavyDataControllers.push_back(newController);
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::setHeavyDataController(std::vector<shared_ptr<XdmfHeavyDataController> > & newControllers)
+{
+ if (mHeavyDataControllers.size() != newControllers.size()) {
+ mHeavyDataControllers.resize(newControllers.size());
+ }
+ for (unsigned int i = 0; i < newControllers.size(); ++i) {
+ mHeavyDataControllers[i] = newControllers[i];
+ }
+ this->setIsChanged(true);
+}
+
+
+void
+XdmfArray::setName(const std::string & name)
+{
+ mName = name;
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::setReadMode(XdmfArray::ReadMode newStatus)
+{
+ mReadMode = newStatus;
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::setReference(shared_ptr<XdmfArrayReference> newReference)
+{
+ mReference = newReference;
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::swap(const shared_ptr<XdmfArray> array)
+{
+ std::swap(mArray, array->mArray);
+ std::swap(mArrayPointerNumValues, array->mArrayPointerNumValues);
+ std::swap(mDimensions, array->mDimensions);
+ std::swap(mHeavyDataControllers, array->mHeavyDataControllers);
+ this->setIsChanged(true);
+}
+
+void
+XdmfArray::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+ if (mReference) {
+ mReference->accept(visitor);
+ }
+}
+
+// C wrappers
+
+XDMFARRAY *
+XdmfArrayNew()
+{
+ try
+ {
+ XDMFARRAY * returnPointer;
+ shared_ptr<XdmfArray> generatedArray = XdmfArray::New();
+ returnPointer = (XDMFARRAY *)((void *)(new XdmfArray(*generatedArray.get())));
+ generatedArray.reset();
+ return returnPointer;
+ }
+ catch (...)
+ {
+ XDMFARRAY * returnPointer;
+ shared_ptr<XdmfArray> generatedArray = XdmfArray::New();
+ returnPointer = (XDMFARRAY *)((void *)(new XdmfArray(*generatedArray.get())));
+ generatedArray.reset();
+ return returnPointer;
+ }
+}
+
+void XdmfArrayClear(XDMFARRAY * array)
+{
+ ((XdmfArray *)(array))->clear();
+}
+
+void XdmfArrayErase(XDMFARRAY * array, unsigned int index)
+{
+ ((XdmfArray *)(array))->erase(index);
+}
+
+int XdmfArrayGetArrayType(XDMFARRAY * array, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<const XdmfArrayType> compareType = ((XdmfArray *)(array))->getArrayType();
+ std::string typeName = compareType->getName();
+ unsigned int typePrecision = compareType->getElementSize();
+ if (typeName == XdmfArrayType::UInt8()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT8;
+ }
+ else if (typeName == XdmfArrayType::UInt16()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT16;
+ }
+ else if (typeName == XdmfArrayType::UInt32()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT32;
+ }
+ else if (typeName == XdmfArrayType::UInt64()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT64;
+ }
+ else if (typeName == XdmfArrayType::Int8()->getName())
+ {
+ return XDMF_ARRAY_TYPE_INT8;
+ }
+ else if (typeName == XdmfArrayType::Int16()->getName())
+ {
+ return XDMF_ARRAY_TYPE_INT16;
+ }
+ else if (typeName == XdmfArrayType::Int32()->getName() || typeName == XdmfArrayType::Int64()->getName())
+ {
+ if (typePrecision == 4)
+ {
+ return XDMF_ARRAY_TYPE_INT32;
+ }
+ else if (typePrecision == 8)
+ {
+ return XDMF_ARRAY_TYPE_INT64;
+ }
+ else
+ {
+ }
+ }
+ else if (typeName == XdmfArrayType::Float32()->getName() || typeName == XdmfArrayType::Float64()->getName())
+ {
+ if (typePrecision == 4)
+ {
+ return XDMF_ARRAY_TYPE_FLOAT32;
+ }
+ else if (typePrecision == 8)
+ {
+ return XDMF_ARRAY_TYPE_FLOAT64;
+ }
+ else
+ {
+ }
+ }
+ else if (typeName == XdmfArrayType::String()->getName())
+ {
+ //This shouldn't be used from C bindings
+ XdmfError::message(XdmfError::FATAL,
+ "Error: String type not usable from C.");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+unsigned int XdmfArrayGetCapacity(XDMFARRAY * array)
+{
+ return ((XdmfArray *)(array))->getCapacity();
+}
+
+unsigned int *
+XdmfArrayGetDimensions(XDMFARRAY * array)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfArray *)(array))->getDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfArray *)(array))->getDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+char *
+XdmfArrayGetDimensionsString(XDMFARRAY * array)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfArray *)(array))->getDimensionsString().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfArray *)(array))->getDimensionsString().c_str());
+ return returnPointer;
+ }
+}
+
+XDMFHEAVYDATACONTROLLER *
+XdmfArrayGetHeavyDataController(XDMFARRAY * array, unsigned int index)
+{
+ return (XDMFHEAVYDATACONTROLLER *)((void *)(((XdmfArray *)(array))->getHeavyDataController(index).get()));
+}
+
+char *
+XdmfArrayGetName(XDMFARRAY * array)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfArray *)(array))->getName().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfArray *)(array))->getName().c_str());
+ return returnPointer;
+ }
+}
+
+unsigned int
+XdmfArrayGetNumberDimensions(XDMFARRAY * array)
+{
+ return ((XdmfArray *)(array))->getDimensions().size();
+}
+
+unsigned int
+XdmfArrayGetNumberHeavyDataControllers(XDMFARRAY * array)
+{
+ return ((XdmfArray *)(array))->getNumberHeavyDataControllers();
+}
+
+unsigned int
+XdmfArrayGetSize(XDMFARRAY * array)
+{
+ return ((XdmfArray *)(array))->getSize();
+}
+
+int
+XdmfArrayGetReadMode(XDMFARRAY * array, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ int readMode = ((XdmfArray *)(array))->getReadMode();
+ switch (readMode) {
+ case XdmfArray::Controller:
+ return XDMF_ARRAY_READ_MODE_CONTROLLER;
+ break;
+ case XdmfArray::Reference:
+ return XDMF_ARRAY_READ_MODE_REFERENCE;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ReadMode.");
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+XDMFARRAYREFERENCE *
+XdmfArrayGetReference(XDMFARRAY * array)
+{
+ return (XDMFARRAYREFERENCE *)((void *)(((XdmfArray *)(array))->getReference().get()));
+}
+
+void *
+XdmfArrayGetValue(XDMFARRAY * array, unsigned int index, int arrayType, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ void * returnVal;
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ returnVal = new unsigned char();
+ *((unsigned char *)returnVal) = ((XdmfArray *)(array))->getValue<unsigned char>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ returnVal = new unsigned short();
+ *((unsigned short *)returnVal) = ((XdmfArray *)(array))->getValue<unsigned short>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ returnVal = new unsigned int();
+ *((unsigned int *)returnVal) = ((XdmfArray *)(array))->getValue<unsigned int>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ returnVal = new uint64_t();
+ *((uint64_t *)returnVal) = ((XdmfArray *)(array))->getValue<uint64_t>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ returnVal = new char();
+ *((char *)returnVal) = ((XdmfArray *)(array))->getValue<char>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ returnVal = new short();
+ *((short *)returnVal) = ((XdmfArray *)(array))->getValue<short>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ returnVal = new int();
+ *((int *)returnVal) = ((XdmfArray *)(array))->getValue<int>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ returnVal = new long();
+ *((long *)returnVal) = ((XdmfArray *)(array))->getValue<long>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ returnVal = new float();
+ *((float *)returnVal) = ((XdmfArray *)(array))->getValue<float>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ returnVal = new double();
+ *((double *)returnVal) = ((XdmfArray *)(array))->getValue<double>(index);
+ return returnVal;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ catch (...)
+ {
+ void * returnVal;
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ returnVal = new unsigned char();
+ *((unsigned char *)returnVal) = ((XdmfArray *)(array))->getValue<unsigned char>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ returnVal = new unsigned short();
+ *((unsigned short *)returnVal) = ((XdmfArray *)(array))->getValue<unsigned short>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ returnVal = new unsigned int();
+ *((unsigned int *)returnVal) = ((XdmfArray *)(array))->getValue<unsigned int>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ returnVal = new uint64_t();
+ *((uint64_t *)returnVal) = ((XdmfArray *)(array))->getValue<uint64_t>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ returnVal = new char();
+ *((char *)returnVal) = ((XdmfArray *)(array))->getValue<char>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ returnVal = new short();
+ *((short *)returnVal) = ((XdmfArray *)(array))->getValue<short>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ returnVal = new int();
+ *((int *)returnVal) = ((XdmfArray *)(array))->getValue<int>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ returnVal = new long();
+ *((long *)returnVal) = ((XdmfArray *)(array))->getValue<long>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ returnVal = new float();
+ *((float *)returnVal) = ((XdmfArray *)(array))->getValue<float>(index);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ returnVal = new double();
+ *((double *)returnVal) = ((XdmfArray *)(array))->getValue<double>(index);
+ return returnVal;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void *
+XdmfArrayGetValues(XDMFARRAY * array, unsigned int startIndex, int arrayType, unsigned int numValues, unsigned int arrayStride, unsigned int valueStride, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ void * returnVal;
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ returnVal = new unsigned char[numValues]();
+ ((XdmfArray *)(array))->getValues<unsigned char>(startIndex, (unsigned char *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ returnVal = new unsigned short[numValues]();
+ ((XdmfArray *)(array))->getValues<unsigned short>(startIndex, (unsigned short *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ returnVal = new unsigned int[numValues]();
+ ((XdmfArray *)(array))->getValues<unsigned int>(startIndex, (unsigned int *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ returnVal = new uint64_t[numValues]();
+ ((XdmfArray *)(array))->getValues<uint64_t>(startIndex, (uint64_t *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ returnVal = new char[numValues]();
+ ((XdmfArray *)(array))->getValues<char>(startIndex, (char *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ returnVal = new short[numValues]();
+ ((XdmfArray *)(array))->getValues<short>(startIndex, (short *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ returnVal = new int[numValues]();
+ ((XdmfArray *)(array))->getValues<int>(startIndex, (int *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ returnVal = new long[numValues]();
+ ((XdmfArray *)(array))->getValues<long>(startIndex, (long *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ returnVal = new float[numValues]();
+ ((XdmfArray *)(array))->getValues<float>(startIndex, (float *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ returnVal = new double[numValues]();
+ ((XdmfArray *)(array))->getValues<double>(startIndex, (double *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ catch (...)
+ {
+ void * returnVal;
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ returnVal = new unsigned char[numValues]();
+ ((XdmfArray *)(array))->getValues<unsigned char>(startIndex, (unsigned char *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ returnVal = new unsigned short[numValues]();
+ ((XdmfArray *)(array))->getValues<unsigned short>(startIndex, (unsigned short *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ returnVal = new unsigned int[numValues]();
+ ((XdmfArray *)(array))->getValues<unsigned int>(startIndex, (unsigned int *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ returnVal = new uint64_t[numValues]();
+ ((XdmfArray *)(array))->getValues<uint64_t>(startIndex, (uint64_t *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ returnVal = new char[numValues]();
+ ((XdmfArray *)(array))->getValues<char>(startIndex, (char *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ returnVal = new short[numValues]();
+ ((XdmfArray *)(array))->getValues<short>(startIndex, (short *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ returnVal = new int[numValues]();
+ ((XdmfArray *)(array))->getValues<int>(startIndex, (int *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ returnVal = new long[numValues]();
+ ((XdmfArray *)(array))->getValues<long>(startIndex, (long *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ returnVal = new float[numValues]();
+ ((XdmfArray *)(array))->getValues<float>(startIndex, (float *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ returnVal = new double[numValues]();
+ ((XdmfArray *)(array))->getValues<double>(startIndex, (double *)returnVal, numValues, arrayStride, valueStride);
+ return returnVal;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void *
+XdmfArrayGetValuesInternal(XDMFARRAY * array)
+{
+ return ((XdmfArray *)(array))->getValuesInternal();
+}
+
+char *
+XdmfArrayGetValuesString(XDMFARRAY * array)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfArray *)(array))->getValuesString().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfArray *)(array))->getValuesString().c_str());
+ return returnPointer;
+ }
+}
+
+void
+XdmfArrayInitialize(XDMFARRAY * array, int * dims, int numDims, int arrayType, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<unsigned int> dimVector((int *)dims, (int *)dims + numDims);
+ shared_ptr<const XdmfArrayType> tempPointer = XdmfArrayType::Uninitialized();
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ tempPointer = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ tempPointer = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ tempPointer = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ tempPointer = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ tempPointer = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ tempPointer = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ tempPointer = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ tempPointer = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ tempPointer = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ tempPointer = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ ((XdmfArray *)(array))->initialize(tempPointer, dimVector);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArrayInsertDataFromPointer(XDMFARRAY * array, void * values, int arrayType, unsigned int startIndex, unsigned int numVals, unsigned int arrayStride, unsigned int valueStride, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)(array))->insert<unsigned char>(startIndex, (unsigned char *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)(array))->insert<unsigned short>(startIndex, (unsigned short *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)(array))->insert<unsigned int>(startIndex, (unsigned int *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)(array))->insert<uint64_t>(startIndex, (uint64_t *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)(array))->insert<char>(startIndex, (char *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)(array))->insert<short>(startIndex, (short *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)(array))->insert<int>(startIndex, (int *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)(array))->insert<long>(startIndex, (long *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)(array))->insert<float>(startIndex, (float *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)(array))->insert<double>(startIndex, (double *)values, numVals, arrayStride, valueStride);
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ catch (...)
+ {
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)(array))->insert<unsigned char>(startIndex, (unsigned char *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)(array))->insert<unsigned short>(startIndex, (unsigned short *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)(array))->insert<unsigned int>(startIndex, (unsigned int *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)(array))->insert<uint64_t>(startIndex, (uint64_t *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)(array))->insert<char>(startIndex, (char *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)(array))->insert<short>(startIndex, (short *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)(array))->insert<int>(startIndex, (int *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)(array))->insert<long>(startIndex, (long *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)(array))->insert<float>(startIndex, (float *)values, numVals, arrayStride, valueStride);
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)(array))->insert<double>(startIndex, (double *)values, numVals, arrayStride, valueStride);
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfArrayInsertDataFromXdmfArray(XDMFARRAY * array, XDMFARRAY * valArray, int * arrayStarts, int * valueStarts, int * arrayCounts, int * valueCounts, int * arrayStrides, int * valueStrides, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ shared_ptr<XdmfArray> tempPointer((XdmfArray *)valArray, XdmfNullDeleter());
+ std::vector<unsigned int> arrayStartVector((int *)arrayStarts, (int *)arrayStarts + ((XdmfArray *)(array))->getDimensions().size());
+ std::vector<unsigned int> valueStartVector((int *)valueStarts, (int *)valueStarts + tempPointer->getDimensions().size());
+ std::vector<unsigned int> arrayCountVector((int *)arrayCounts, (int *)arrayCounts + ((XdmfArray *)(array))->getDimensions().size());
+ std::vector<unsigned int> valueCountVector((int *)valueCounts, (int *)valueCounts + tempPointer->getDimensions().size());
+ std::vector<unsigned int> arrayStrideVector((int *)arrayStrides, (int *)arrayStrides + ((XdmfArray *)(array))->getDimensions().size());
+ std::vector<unsigned int> valueStrideVector((int *)valueStrides, (int *)valueStrides + tempPointer->getDimensions().size());
+ ((XdmfArray *)(array))->insert(arrayStartVector, tempPointer, valueStartVector, arrayCountVector, valueCountVector, arrayStrideVector, valueStrideVector);
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfArray> tempPointer((XdmfArray *)valArray, XdmfNullDeleter());
+ std::vector<unsigned int> arrayStartVector((int *)arrayStarts, (int *)arrayStarts + ((XdmfArray *)(array))->getDimensions().size());
+ std::vector<unsigned int> valueStartVector((int *)valueStarts, (int *)valueStarts + tempPointer->getDimensions().size());
+ std::vector<unsigned int> arrayCountVector((int *)arrayCounts, (int *)arrayCounts + ((XdmfArray *)(array))->getDimensions().size());
+ std::vector<unsigned int> valueCountVector((int *)valueCounts, (int *)valueCounts + tempPointer->getDimensions().size());
+ std::vector<unsigned int> arrayStrideVector((int *)arrayStrides, (int *)arrayStrides + ((XdmfArray *)(array))->getDimensions().size());
+ std::vector<unsigned int> valueStrideVector((int *)valueStrides, (int *)valueStrides + tempPointer->getDimensions().size());
+ ((XdmfArray *)(array))->insert(arrayStartVector, tempPointer, valueStartVector, arrayCountVector, valueCountVector, arrayStrideVector, valueStrideVector);
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArrayInsertHeavyDataController(XDMFARRAY * array, XDMFHEAVYDATACONTROLLER * controller, int passControl)
+{
+ if (passControl == 0) {
+ ((XdmfArray *)(array))->insert(shared_ptr<XdmfHeavyDataController>((XdmfHeavyDataController *) controller, XdmfNullDeleter()));
+ }
+ else {
+ ((XdmfArray *)(array))->insert(shared_ptr<XdmfHeavyDataController>((XdmfHeavyDataController *) controller));
+ }
+}
+
+void
+XdmfArrayInsertValue(XDMFARRAY * array, unsigned int index, void * value, int arrayType, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)(array))->insert(index, *((unsigned char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)(array))->insert(index, *((unsigned short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)(array))->insert(index, *((unsigned int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)(array))->insert(index, *((uint64_t *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)(array))->insert(index, *((char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)(array))->insert(index, *((short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)(array))->insert(index, *((int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)(array))->insert(index, *((long *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)(array))->insert(index, *((float *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)(array))->insert(index, *((double *)value));
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ catch (...)
+ {
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)(array))->insert(index, *((unsigned char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)(array))->insert(index, *((unsigned short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)(array))->insert(index, *((unsigned int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)(array))->insert(index, *((uint64_t *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)(array))->insert(index, *((char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)(array))->insert(index, *((short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)(array))->insert(index, *((int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)(array))->insert(index, *((long *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)(array))->insert(index, *((float *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)(array))->insert(index, *((double *)value));
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+int
+XdmfArrayIsInitialized(XDMFARRAY * array)
+{
+ return ((XdmfArray *)(array))->isInitialized();
+}
+
+void
+XdmfArrayPushBack(XDMFARRAY * array, void * value, int arrayType, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)(array))->pushBack<unsigned char>(*((unsigned char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)(array))->pushBack<unsigned short>(*((unsigned short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)(array))->pushBack<unsigned int>(*((unsigned int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)(array))->pushBack<uint64_t>(*((uint64_t *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)(array))->pushBack<char>(*((char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)(array))->pushBack<short>(*((short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)(array))->pushBack<int>(*((int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)(array))->pushBack<long>(*((long *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)(array))->pushBack<float>(*((float *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)(array))->pushBack<double>(*((double *)value));
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ catch (...)
+ {
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)(array))->pushBack<unsigned char>(*((unsigned char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)(array))->pushBack<unsigned short>(*((unsigned short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)(array))->pushBack<unsigned int>(*((unsigned int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)(array))->pushBack<uint64_t>(*((uint64_t *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)(array))->pushBack<char>(*((char *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)(array))->pushBack<short>(*((short *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)(array))->pushBack<int>(*((int *)value));
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)(array))->pushBack<long>(*((long *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)(array))->pushBack<float>(*((float *)value));
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)(array))->pushBack<double>(*((double *)value));
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArrayRead(XDMFARRAY * array, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ ((XdmfArray *)(array))->read();
+ }
+ catch (...)
+ {
+ ((XdmfArray *)(array))->read();
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArrayReadController(XDMFARRAY * array, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ ((XdmfArray *)(array))->readController();
+ }
+ catch (...)
+ {
+ ((XdmfArray *)(array))->readController();
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArrayReadReference(XDMFARRAY * array, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ ((XdmfArray *)(array))->readReference();
+ }
+ catch (...)
+ {
+ ((XdmfArray *)(array))->readReference();
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArrayRelease(XDMFARRAY * array)
+{
+ ((XdmfArray *)(array))->release();
+}
+
+void
+XdmfArrayRemoveHeavyDataController(XDMFARRAY * array, unsigned int index)
+{
+ ((XdmfArray *)(array))->removeHeavyDataController(index);
+}
+
+void
+XdmfArrayReserve(XDMFARRAY * array, int size)
+{
+ ((XdmfArray *)(array))->reserve(size);
+}
+
+void
+XdmfArrayResize(XDMFARRAY * array, int * dims, int numDims, int arrayType, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<unsigned int> dimVector((int *)dims, (int *)dims + numDims);
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (unsigned char) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT16:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (unsigned short) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT32:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (unsigned int) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT64:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (uint64_t) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT8:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (char) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT16:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (short) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT32:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (int) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT64:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (long) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (float) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (double) 0);
+ break;
+ }
+ default:
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ dimVector.clear();
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> dimVector((int *)dims, (int *)dims + numDims);
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (unsigned char) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT16:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (unsigned short) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT32:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (unsigned int) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT64:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (uint64_t) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT8:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (char) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT16:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (short) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT32:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (int) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT64:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (long) 0);
+ break;
+ }
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (float) 0);
+ break;
+ }
+
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ {
+ XdmfArray * classedArray = (XdmfArray *)((void *) array);
+ classedArray->resize(dimVector, (double) 0);
+ break;
+ }
+ default:
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ }
+ dimVector.clear();
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArraySetReadMode(XDMFARRAY * array, int readMode, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (readMode) {
+ case XDMF_ARRAY_READ_MODE_CONTROLLER:
+ ((XdmfArray *)(array))->setReadMode(XdmfArray::Controller);
+ break;
+ case XDMF_ARRAY_READ_MODE_REFERENCE:
+ ((XdmfArray *)(array))->setReadMode(XdmfArray::Reference);
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ReadMode.");
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArraySetReference(XDMFARRAY * array, XDMFARRAYREFERENCE * reference, int passControl)
+{
+ if (passControl) {
+ ((XdmfArray *)(array))->setReference(shared_ptr<XdmfArrayReference>((XdmfArrayReference *)reference));
+ }
+ else {
+ ((XdmfArray *)(array))->setReference(shared_ptr<XdmfArrayReference>((XdmfArrayReference *)reference, XdmfNullDeleter()));
+ }
+}
+
+void
+XdmfArraySetName(XDMFARRAY * array, char * name, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfArray *)(array))->setName(name);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArraySetValuesInternal(XDMFARRAY * array, void * pointer, unsigned int numValues, int arrayType, int transferOwnership, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ ((XdmfArray *)array)->setValuesInternal((unsigned char *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ ((XdmfArray *)array)->setValuesInternal((unsigned short *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ ((XdmfArray *)array)->setValuesInternal((unsigned int *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ ((XdmfArray *)array)->setValuesInternal((uint64_t *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ ((XdmfArray *)array)->setValuesInternal((char *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ ((XdmfArray *)array)->setValuesInternal((short *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ ((XdmfArray *)array)->setValuesInternal((int *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ ((XdmfArray *)array)->setValuesInternal((long *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ ((XdmfArray *)array)->setValuesInternal((float *)pointer, numValues, transferOwnership);
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ ((XdmfArray *)array)->setValuesInternal((double *)pointer, numValues, transferOwnership);
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfArraySwapWithXdmfArray(XDMFARRAY * array, XDMFARRAY * swapArray)
+{
+ shared_ptr<XdmfArray> pointerToSwap((XdmfArray *) swapArray, XdmfNullDeleter());
+ ((XdmfArray *)array)->swap(pointerToSwap);
+}
+
+void
+XdmfArraySwapWithArray(XDMFARRAY * array, void ** pointer, int numValues, int arrayType, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (arrayType) {
+ case XDMF_ARRAY_TYPE_UINT8: {
+ std::vector<unsigned char> swapVector((unsigned char *)(*pointer), (unsigned char *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new unsigned char[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((unsigned char *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT16: {
+ std::vector<unsigned short> swapVector((unsigned short *)(*pointer), (unsigned short *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new unsigned short[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((unsigned short *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT32: {
+ std::vector<unsigned int> swapVector((unsigned int *)(*pointer), (unsigned int *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new unsigned int[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((unsigned int *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_UINT64: {
+ std::vector<uint64_t> swapVector((uint64_t *)(*pointer), (uint64_t *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new uint64_t[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((uint64_t *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT8: {
+ std::vector<char> swapVector((char *)(*pointer), (char *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new char[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((char *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT16: {
+ std::vector<short> swapVector((short *)(*pointer), (short *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new short[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((short *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT32: {
+ std::vector<int> swapVector((int *)(*pointer), (int *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new int[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((int *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_INT64: {
+ std::vector<long> swapVector((long *)(*pointer), (long *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new long[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((long *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_FLOAT32: {
+ std::vector<float> swapVector((float *)(*pointer), (float *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new float[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((float *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ case XDMF_ARRAY_TYPE_FLOAT64: {
+ std::vector<double> swapVector((double *)(*pointer), (double *)(*pointer) + numValues);
+ ((XdmfArray *)array)->swap(swapVector);
+ *pointer = new double[swapVector.size()];
+ for (unsigned int i = 0; i < swapVector.size(); ++i)
+ {
+ ((double *) (*pointer))[i] = swapVector[i];
+ }
+ break;
+ }
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfArray, XDMFARRAY)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfArray.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFARRAY_HPP_
+#define XDMFARRAY_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfArrayReference.hpp"
+#include "XdmfHeavyDataController.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArrayType;
+class XdmfHeavyDataController;
+
+// Includes
+#include <boost/shared_array.hpp>
+
+// in order to support uint64 type, we need to increase the number of types
+// that can be used in a boost::variant
+// note : available values for BOOST_MPL_LIMIT_LIST_SIZE are 10, 20, 30, 40 and 50,
+// default is 20, which not enough, so increase to 30
+#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
+#if !defined(BOOST_MPL_LIMIT_LIST_SIZE)
+#define BOOST_MPL_LIMIT_LIST_SIZE 30
+#elif BOOST_MPL_LIMIT_LIST_SIZE < 30
+#undef BOOST_MPL_LIMIT_LIST_SIZE
+#define BOOST_MPL_LIMIT_LIST_SIZE 30
+#endif
+#include <boost/variant.hpp>
+
+/**
+ * @brief Provides storage for data values that are read in or will be
+ * written to heavy data on disk.
+ *
+ * XdmfArray provides a single interface for storing a variety of data
+ * types. The data type stored is determined by the type initially
+ * inserted into the array. An array can be initialized with a
+ * specific data type before insertion of values by calling
+ * initialize().
+ *
+ * An XdmfArray is associated with heavy data files on disk through an
+ * XdmfHeavyDataController. When an Xdmf file is read from disk,
+ * XdmfHeavyDataControllers are attached to all created XdmfArrays
+ * that contain values stored in heavy data. These values are not read
+ * into memory when the Xdmf file is parsed. The array is
+ * uninitialized and the return value of isInitialized() is false. In
+ * order to read the heavy data values into memory, read() must be
+ * called. This will cause the array to ask for values to be read from
+ * disk using the XdmfHeavyDataController. After the values have been
+ * read from heavy data on disk, isInitialized() will return true.
+ *
+ * This version of Xdmf allows for multiple controllers to be added to
+ * a single array. Be aware that doing this makes the files written
+ * incompatible with previous editions.
+ *
+ * XdmfArray allows for insertion and retrieval of data in two
+ * fundamental ways:
+ *
+ * By Copy:
+ *
+ * getValue
+ * getValues
+ * insert
+ * pushBack
+ *
+ * XdmfArray stores its own copy of the data. Modifications to the
+ * data stored in the XdmfArray will not change values stored in the
+ * original array.
+ *
+ * By Shared Reference:
+ *
+ * getValuesInternal
+ * setValuesInternal
+ *
+ * XdmfArray shares a reference to the data. No copy is
+ * made. XdmfArray holds a shared pointer to the original data.
+ * Modifications to the data stored in the XdmfArray also causes
+ * modification to values stored in the original array.
+ *
+ * Xdmf supports the following datatypes:
+ * Int8
+ * Int16
+ * Int32
+ * Int64
+ * Float32
+ * Float64
+ * UInt8
+ * UInt16
+ * UInt32
+ * UInt64
+ * String
+ */
+class XDMFCORE_EXPORT XdmfArray : public XdmfItem {
+
+public:
+
+ enum ReadMode {
+ Controller,
+ Reference
+ };
+
+ /**
+ * Create a new XdmfArray.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfArray.
+ */
+ static shared_ptr<XdmfArray> New();
+
+ virtual ~XdmfArray();
+
+ LOKI_DEFINE_VISITABLE(XdmfArray, XdmfItem)
+ XDMF_CHILDREN(XdmfArray, XdmfHeavyDataController, HeavyDataController, Name)
+ static const std::string ItemTag;
+
+ /**
+ * Remove all values from this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#clear
+ * @until //#clear
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//clear
+ * @until #//clear
+ */
+ void clear();
+
+ /**
+ * Remove a value from this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#erase
+ * @until //#erase
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//arraydefaultvalues
+ * @until #//arraydefaultvalues
+ * @skipline #//erase
+ * @until #//erase
+ *
+ * @param index The index of the value to be removed
+ */
+ void erase(const unsigned int index);
+
+ /**
+ * Get the data type of this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getArrayType
+ * @until //#getArrayType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getArrayType
+ * @until #//getArrayType
+ *
+ * @return An XdmfArrayType containing the data type for the array.
+ */
+ shared_ptr<const XdmfArrayType> getArrayType() const;
+
+ /**
+ * Get the capacity of this array, the number of values the array
+ * can store without reallocation.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getCapacity
+ * @until //#getCapacity
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getCapacity
+ * @until #//getCapacity
+ *
+ * @return The capacity of this array.
+ */
+ unsigned int getCapacity() const;
+
+ /**
+ * Get the dimensions of the array.
+ * If the array isn't initialized the dimensions
+ * will be based on the heavyDataControllers it has, if any.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return The dimensions of the array.
+ */
+ std::vector<unsigned int> getDimensions() const;
+
+ /**
+ * Get the dimensions of the array as a string.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDimensionsString
+ * @until //#getDimensionsString
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDimensionsString
+ * @until #//getDimensionsString
+ *
+ * @return The dimensions of the array as a string.
+ */
+ std::string getDimensionsString() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the name of the array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return A string containing the name of the array.
+ */
+ virtual std::string getName() const;
+
+ /**
+ * Gets the method this array will be written/read.
+ * Possible choices are: Controller, and Reference
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setReference
+ * @until //#setReference
+ * @skipline //#setReadMode
+ * @until //#setReadMode
+ * @skipline //#getReadMode
+ * @until //#getReadMode
+ *
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setReference
+ * @until #//setReference
+ * @skipline #//setReadMode
+ * @until #//setReadMode
+ * @skipline #//getReadMode
+ * @until #//getReadMode
+ *
+ * @return What method will be used when reading/writing the array
+ */
+ ReadMode getReadMode() const;
+
+ /**
+ * Get the number of values stored in this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getSize
+ * @until //#getSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getSize
+ * @until #//getSize
+ *
+ * @return The number of values stored in this array.
+ */
+ unsigned int getSize() const;
+
+ /**
+ * Gets the array reference that the array will pull from when reading from a reference.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setReference
+ * @until //#setReference
+ * @skipline //#getReference
+ * @until //#getReference
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setReference
+ * @until #//setReference
+ * @skipline #//getReference
+ * @until #//getReference
+ *
+ * @return The reference being pulled from
+ */
+ shared_ptr<XdmfArrayReference> getReference();
+
+ /**
+ * Get a copy of a single value stored in this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#datapointersetup
+ * @until //#datapointersetup
+ * @skipline //#initsharedvector
+ * @until //#initsharedvector
+ * @skipline //#getValueindex
+ * @until //#getValueindex
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//arraydefaultvalues
+ * @until #//arraydefaultvalues
+ * @skipline #//getValueindex
+ * @until #//getValueindex
+ *
+ * @return The requested value.
+ */
+ template <typename T>
+ T getValue(const unsigned int index) const;
+
+ /**
+ * Get a copy of the values stored in this array
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getValues
+ * @until //#getValues
+ *
+ * Python:
+ * This function is not supported in Python,
+ * it is replaced by the getNumpyArray function
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//arraydefaultvalues
+ * @until #//arraydefaultvalues
+ * @skipline #//getNumpyArray
+ * @until #//getNumpyArray
+ *
+ * @param startIndex The index in this array to begin copying from.
+ * @param valuesPointer A pointer to an array to copy into.
+ * @param numValues The number of values to copy.
+ * @param arrayStride Number of values to stride in this array
+ * between each copy.
+ * @param valuesStride Number of values to stride in the pointer
+ * between each copy.
+ */
+ template <typename T> void
+ getValues(const unsigned int startIndex,
+ T * const valuesPointer,
+ const unsigned int numValues = 1,
+ const unsigned int arrayStride = 1,
+ const unsigned int valuesStride = 1) const;
+
+ /**
+ * Get a smart pointer to the internal values stored in this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getValuesInternalvector
+ * @until //#getValuesInternalvector
+ *
+ * Python:
+ * Python does not support this version of the getValuesInternal function,
+ * it defaults to the version that returns a void pointer
+ *
+ * @return A smart pointer to the internal vector of values stored
+ * in this array.
+ */
+ template <typename T>
+ shared_ptr<std::vector<T> > getValuesInternal();
+
+ /**
+ * Get a pointer to the internal values stored in this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getValuesInternalvoid
+ * @until //#getValuesInternalvoid
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline #//getValuesInternal
+ * @until #//getValuesInternal
+ *
+ * @return A void pointer to the first value stored in this array.
+ */
+ void * getValuesInternal();
+
+ /**
+ * Get a pointer to the internal values stored in this array (const
+ * version).
+ *
+ * Example of use:
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getValuesInternalvoidconst
+ * @until //#getValuesInternalvoidconst
+ *
+ * Python:
+ * Python does not support this version of the getValuesInternal function,
+ * it defaults to the version that returns a void pointer
+ *
+ * @return A void pointer to the first value stored in this array.
+ */
+ const void * getValuesInternal() const;
+
+ /**
+ * Get the values stored in this array as a string.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getValuesString
+ * @until //#getValuesString
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getValuesparse
+ * @until #//getValuesparse
+ *
+ * @return A string containing the contents of the array.
+ */
+ std::string getValuesString() const;
+
+ /**
+ * Initialize the array to a specific size.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizedeclaration
+ * @until //#sizedeclaration
+ * @skipline //#initializesingletemplate
+ * @until //#initializesingletemplate
+ *
+ * Python: Does not support this version of initialize
+ *
+ * @param size The number of values in the initialized array.
+ *
+ * @return A smart pointer to the internal vector of values
+ * initialized in this array.
+ */
+ template <typename T>
+ shared_ptr<std::vector<T> > initialize(const unsigned int size = 0);
+
+ /**
+ * Initialize the array to specific dimensions.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizevectordeclaration
+ * @until //#sizevectordeclaration
+ * @skipline //#initializevectortemplate
+ * @until //#initializevectortemplate
+ *
+ * Python: Does not support this version of initialize
+ *
+ * @param dimensions The dimensions of the initialized array.
+ *
+ * @return A smart pointer to the internal vector of values
+ * initialized in this array.
+ */
+ template <typename T>
+ shared_ptr<std::vector<T> >
+ initialize(const std::vector<unsigned int> & dimensions);
+
+ /**
+ * Initialize the array to contain a specified amount of a particular type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizedeclaration
+ * @until //#sizedeclaration
+ * @skipline //#initializesingletype
+ * @until //#initializesingletype
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//initializesingle
+ * @until #//initializesingle
+ *
+ * @param arrayType The type of array to initialize.
+ * @param size The number of values in the initialized array.
+ */
+ void initialize(const shared_ptr<const XdmfArrayType> & arrayType,
+ const unsigned int size = 0);
+
+ /**
+ * Initialize the array with specified dimensions to contain a particular type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizevectordeclaration
+ * @until //#sizevectordeclaration
+ * @skipline //#initializevectortype
+ * @until //#initializevectortype
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//initializevector
+ * @until #//initializevector
+ *
+ * @param arrayType The type of array to initialize.
+ * @param dimensions The number dimensions of the initialized array.
+ */
+ void initialize(const shared_ptr<const XdmfArrayType> & arrayType,
+ const std::vector<unsigned int> & dimensions);
+
+ using XdmfItem::insert;
+
+ /**
+ * Insert value into this array
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#pointinsertvalues
+ * @until //#pointinsertvalues
+ * @skipline //#pointinsert
+ * @until //#pointinsert
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//pointinsert
+ * @until #//pointinsert
+ *
+ * @param index The index in this array to insert.
+ * @param value The value to insert
+ */
+ template<typename T>
+ void insert(const unsigned int index,
+ const T & value);
+
+ /**
+ * Insert values from an XdmfArray into this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#datapointersetup
+ * @until //#datapointersetup
+ * @skipline //#pointerinsert
+ * @until //#pointerinsert
+ * @skipline //#arrayinsert
+ * @until //#arrayinsert
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//insertarray
+ * @until #//insertarray
+ *
+ * @param startIndex The index in this array to begin insertion.
+ * @param values A shared pointer to an XdmfArray to copy
+ * into this array.
+ * @param valuesStartIndex The index in the XdmfArray to begin copying.
+ * @param numValues The number of values to copy into this array.
+ * @param arrayStride Number of values to stride in this array
+ * between each copy.
+ * @param valuesStride Number of values to stride in the XdmfArray
+ * between each copy.
+ */
+ void insert(const unsigned int startIndex,
+ const shared_ptr<const XdmfArray> values,
+ const unsigned int valuesStartIndex = 0,
+ const unsigned int numValues = 1,
+ const unsigned int arrayStride = 1,
+ const unsigned int valuesStride = 1);
+
+ /**
+ * Insert values from an XdmfArray into this array. This is the multidimensional version.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#insertmultidim
+ * @until //#insertmultidim
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//insertmultidim
+ * @until #//insertmultidim
+ *
+ * @param startIndex The index in this array to begin
+ * insertion for each dimension
+ * @param values A shared pointer to an XdmfArray
+ * to copy into this array.
+ * @param valuesStartIndex The index in the XdmfArray to begin
+ * copying for each dimension of the
+ * source array
+ * @param numValues The number of values to copy into this
+ * array for each dimension on the
+ * source array
+ * @param numInserted The number of strides to make across
+ * the array being written to for each
+ * dimension
+ * @param arrayStride Number of values to stride in this array
+ * between each copy for each dimension
+ * @param valuesStride Number of values to stride in the
+ * XdmfArray between each copy for each
+ * dimension of the source array
+ */
+ void insert(const std::vector<unsigned int> startIndex,
+ const shared_ptr<const XdmfArray> values,
+ const std::vector<unsigned int> valuesStartIndex,
+ const std::vector<unsigned int> numValues,
+ const std::vector<unsigned int> numInserted,
+ const std::vector<unsigned int> arrayStride,
+ const std::vector<unsigned int> valuesStride);
+
+ /**
+ * Insert values into this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#datapointersetup
+ * @until //#datapointersetup
+ * @skipline //#pointerinsert
+ * @until //#pointerinsert
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//insertlist
+ * @until #//insertlist
+ *
+ * @param startIndex The index in this array to begin insertion.
+ * @param valuesPointer A pointer to the values to copy into this array.
+ * @param numValues The number of values to copy into this array.
+ * @param arrayStride Number of values to stride in this array between
+ * each copy.
+ * @param valuesStride Number of values to stride in the pointer between
+ * each copy.
+ */
+ template<typename T>
+ void insert(const unsigned int startIndex,
+ const T * const valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride = 1,
+ const unsigned int valuesStride = 1);
+
+ /**
+ * Returns whether the array is initialized (contains values in
+ * memory).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#isInitialized
+ * @until //#isInitialized
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//isInitialized
+ * @until #//isInitialized
+ */
+ virtual bool isInitialized() const;
+
+ /**
+ * Copy a value to the back of this array
+ *
+ * Example of use;
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#pointinsertvalues
+ * @until //#pointinsertvalues
+ * @skipline //#pushBack
+ * @until //#pushBack
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//pushBack
+ * @until #//pushBack
+ *
+ * @param value The value to be inserted
+ */
+ template <typename T>
+ void pushBack(const T & value);
+
+ /**
+ * Get the first heavy data controller attached to this array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getHeavyDataController
+ * @until //#getHeavyDataController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getHeavyDataController
+ * @until #//getHeavyDataController
+ *
+ * @return The heavy data controller attached to this array.
+ */
+ shared_ptr<XdmfHeavyDataController>
+ getHeavyDataController();
+
+ /**
+ * Get the first heavy data controller attached to this array. (const version)
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getHeavyDataControllerconst
+ * @until //#getHeavyDataControllerconst
+ *
+ * Python: Doesn't support a constant version of this function
+ *
+ * @return The heavy data controller attached to this array.
+ */
+ shared_ptr<const XdmfHeavyDataController>
+ getHeavyDataController() const;
+
+ /**
+ * Replace all controllers attached to this array with the controller provided.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getHeavyDataController
+ * @until //#getHeavyDataController
+ * @skipline //#setHeavyDataController
+ * @until //#setHeavyDataController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getHeavyDataController
+ * @until #//getHeavyDataController
+ * @skipline #//setHeavyDataController
+ * @until #//setHeavyDataController
+ *
+ * @param newController The heavy data controller to attach to this array.
+ */
+ void
+ setHeavyDataController(shared_ptr<XdmfHeavyDataController> newController);
+
+ /**
+ * Sets the controllers attached to this array to the ones contained
+ * in the provided vector.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setHeavyDataControllerVector
+ * @until //#setHeavyDataControllerVector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setHeavyDataControllerVector
+ * @until #//setHeavyDataControllerVector
+ *
+ * @param newControllers The controllers to be set to the array.
+ */
+ void
+ setHeavyDataController(std::vector<shared_ptr<XdmfHeavyDataController> > & newControllers);
+
+
+ /**
+ * Read data from disk into memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//isInitialized
+ * @until #//isInitialized
+ */
+ void read();
+
+ /**
+ * Reads data from the attached controllers to the internal data storage.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getHeavyDataController
+ * @until //#getHeavyDataController
+ * @skipline //#setHeavyDataController
+ * @until //#setHeavyDataController
+ * @skipline //#readController
+ * @until //#readController
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getHeavyDataController
+ * @until #//getHeavyDataController
+ * @skipline #//setHeavyDataController
+ * @until #//setHeavyDataController
+ * @skipline #//readController
+ * @until #//readController
+ */
+ void readController();
+
+ /**
+ * Reads the data pointed to by the array reference into the array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setReference
+ * @until //#setReference
+ * @skipline //#readReference
+ * @until //#readReference
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setReference
+ * @until #//setReference
+ * @skipline #//readReference
+ * @until #//readReference
+ */
+ void readReference();
+
+ /**
+ * Release all data currently held in memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#release
+ * @until //#release
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//release
+ * @until #//release
+ */
+ void release();
+
+ /**
+ * Set the capacity of the array to at least size.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizedeclaration
+ * @until //#sizedeclaration
+ * @skipline //#reserve
+ * @until //#reserve
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//reserve
+ * @until #//reserve
+ *
+ * @param size The capacity to set this array to.
+ */
+ void reserve(const unsigned int size);
+
+ /**
+ * Resizes the array to contain a number of values. If numValues is
+ * larger than the current size, values are appended to the end of
+ * the array equal to value. If numValues is less than the current
+ * size, values at indices larger than numValues are removed.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizedeclaration
+ * @until //#sizedeclaration
+ * @skipline //#resizesingle
+ * @until //#resizesingle
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//arraydefaultvalues
+ * @until #//arraydefaultvalues
+ * @skipline #//resizesingle
+ * @until #//resizesingle
+ *
+ * @param numValues The number of values to resize this array to.
+ * @param value The number to initialize newly created
+ * values to, if needed.
+ */
+ template<typename T>
+ void resize(const unsigned int numValues,
+ const T & value = 0);
+
+ /**
+ * Resizes the array to specified dimensions. If the number of
+ * values specified by the dimensions is larger than the current
+ * size, values are appended to the end of the array equal to
+ * value. If numValues is less than the current size, values at
+ * indices larger than numValues are removed.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#sizevectordeclaration
+ * @until //#sizevectordeclaration
+ * @skipline //#resizevector
+ * @until //#resizevector
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//arraydefaultvalues
+ * @until #//arraydefaultvalues
+ * @skipline #//resizevector
+ * @until #//resizevector
+ *
+ * @param dimensions The dimensions to resize the array to.
+ * @param value The number to intialize newly created values to,
+ * if needed.
+ */
+ template<typename T>
+ void resize(const std::vector<unsigned int> & dimensions,
+ const T & value = 0);
+
+ /**
+ * Sets the array reference from which the Array will fill when readReference is called.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setReference
+ * @until //#setReference
+ *
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setReference
+ * @until #//setReference
+ *
+ * @param newReference The reference to be associated with this array
+ */
+ void setReference(shared_ptr<XdmfArrayReference> newReference);
+
+ /**
+ * Set the name of the array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ *
+ * @param name Name of the array to set.
+ */
+ virtual void setName(const std::string & name);
+
+ /**
+ * Sets the method this array will be written/read.
+ * Possible choices are: Controller, and Reference
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setReference
+ * @until //#setReference
+ * @skipline //#setReadMode
+ * @until //#setReadMode
+ *
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setReference
+ * @until #//setReference
+ * @skipline #//setReadMode
+ * @until #//setReadMode
+ *
+ * @param newStatus The method that the array will be read/written
+ */
+ void setReadMode(ReadMode newStatus = XdmfArray::Controller);
+
+ /**
+ * Sets the values of this array to the values stored in the
+ * arrayPointer array. No copy is made. Modifications to the array
+ * are not permitted through the XdmfArray API. Any calls through
+ * the XdmfArray API to modify the array (i.e. any non-const
+ * function) will result in the array being copied into internal
+ * storage. The internal copy is then modified. This prevents
+ * situations where a realloc of the pointer could cause other
+ * references to become invalid. The caller of this method can
+ * continue to modify the values stored in arrayPointer on its
+ * own. This function is meant for applications that have their own
+ * array data structures that merely use Xdmf to output the data, an
+ * operation that should not require a copy. Other applications that
+ * use Xdmf for in memory data storage should avoid this function.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#datapointersetup
+ * @until //#datapointersetup
+ * @skipline //#setValuesInternalpointer
+ * @until //#setValuesInternalpointer
+ *
+ * Python: does not support setValuesInternal
+ *
+ * @param arrayPointer A pointer to an array to store in
+ * this XdmfArray.
+ * @param numValues The number of values in the array.
+ * @param transferOwnership Whether to transfer responsibility for
+ * deletion of the array to XdmfArray.
+ */
+ template<typename T>
+ void setValuesInternal(const T * const arrayPointer,
+ const unsigned int numValues,
+ const bool transferOwnership = 0);
+
+ /**
+ * Sets the values of this array to the values stored in the
+ * vector. No copy is made. The caller of this method retains
+ * ownership of the data and must ensure that the array is still
+ * valid for the entire time Xdmf needs it.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#initinternalvector
+ * @until //#initinternalvector
+ * @skipline //#setValuesInternalvector
+ * @until //#setValuesInternalvector
+ *
+ * Python: does not support setValuesInternal
+ *
+ * @param array A vector to store in this XdmfArray.
+ * @param transferOwnership Whether to transfer responsibility for
+ * deletion of the array to XdmfArray.
+ */
+ template<typename T>
+ void setValuesInternal(std::vector<T> & array,
+ const bool transferOwnership = 0);
+
+ /**
+ * Sets the values of this array to the values stored in the
+ * vector. No copy is made. This array shares ownership with other
+ * references to the smart pointer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#initinternalvector
+ * @until //#initinternalvector
+ * @skipline //#initsharedvector
+ * @until //#initsharedvector
+ * @skipline //#setValuesInternalsharedvector
+ * @until //#setValuesInternalsharedvector
+ *
+ * Python: does not support setValuesInternal
+ *
+ * @param array A smart pointer to a vector to store in this array.
+ */
+ template<typename T>
+ void setValuesInternal(const shared_ptr<std::vector<T> > array);
+
+ /**
+ * Exchange the contents of the vector with the contents of this
+ * array. No copy is made. The internal arrays are swapped.
+ *
+ * Example of use
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#initinternalvector
+ * @until //#initinternalvector
+ * @skipline //#swapvector
+ * @until //#swapvector
+ *
+ * Python: The Python version only supports swapping XdmfArrays
+ *
+ * @param array A vector to exchange values with.
+ * @return bool whether the swap was successful.
+ */
+ template<typename T>
+ bool swap(std::vector<T> & array);
+
+ /**
+ * Exchange the contents of the vector with the contents of this
+ * array. No copy is made. The internal arrays are swapped.
+ *
+ * Example of use
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#initinternalvector
+ * @until //#initinternalvector
+ * @skipline //#initsharedvector
+ * @until //#initsharedvector
+ * @skipline //#swapsharedvector
+ * @until //#swapsharedvector
+ *
+ * Python: The Python version only supports swapping XdmfArrays
+ *
+ * @param array A smart pointer to a vector to exchange values with.
+ * @return bool whether the swap was successful.
+ */
+ template<typename T>
+ bool swap(const shared_ptr<std::vector<T> > array);
+
+ /**
+ * Exchange the contents of an XdmfArray with the contents of this
+ * array. No copy is made. The internal arrays are swapped.
+ *
+ * Example of use
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArray.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#swaparray
+ * @until //#swaparray
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArray.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//arraydefaultvalues
+ * @until #//arraydefaultvalues
+ * @skipline //#swap
+ * @until //#swap
+ *
+ * @param array A smart pointer to a vector to exchange values with.
+ */
+ void swap(const shared_ptr<XdmfArray> array);
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfArray(XdmfArray &);
+
+protected:
+
+ XdmfArray();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfArray(const XdmfArray &); // Not implemented.
+ void operator=(const XdmfArray &); // Not implemented.
+
+ // Variant Visitor Operations
+ class Clear;
+ class Erase;
+ class GetArrayType;
+ class GetCapacity;
+ template <typename T> class GetValue;
+ template <typename T> class GetValues;
+ class GetValuesPointer;
+ class GetValuesString;
+ template <typename T> class Insert;
+ class InsertArray;
+ class InternalizeArrayPointer;
+ class IsInitialized;
+ struct NullDeleter;
+ template <typename T> class PushBack;
+ class Reserve;
+ template <typename T> class Resize;
+ class Size;
+
+ /**
+ * After setValues() is called, XdmfArray stores a pointer that is
+ * not allowed to be modified through the XdmfArray API. If the user
+ * desires to modify the contents of the pointer, they must do so
+ * without calling any non-const functions of XdmfArray. If they do
+ * call non-const functions of XdmfArray, we attempt to accommodate
+ * by copying the array pointer into internal data structures.
+ */
+ void internalizeArrayPointer();
+
+ typedef boost::variant<
+ boost::blank,
+ shared_ptr<std::vector<char> >,
+ shared_ptr<std::vector<short> >,
+ shared_ptr<std::vector<int> >,
+ shared_ptr<std::vector<long> >,
+ shared_ptr<std::vector<float> >,
+ shared_ptr<std::vector<double> >,
+ shared_ptr<std::vector<unsigned char> >,
+ shared_ptr<std::vector<unsigned short> >,
+ shared_ptr<std::vector<unsigned int> >,
+ shared_ptr<std::vector<unsigned long> >,
+ shared_ptr<std::vector<uint64_t> >,
+ shared_ptr<std::vector<std::string> >,
+ boost::shared_array<const char>,
+ boost::shared_array<const short>,
+ boost::shared_array<const int>,
+ boost::shared_array<const long>,
+ boost::shared_array<const float>,
+ boost::shared_array<const double>,
+ boost::shared_array<const unsigned char>,
+ boost::shared_array<const unsigned short>,
+ boost::shared_array<const unsigned int>,
+ boost::shared_array<const unsigned long>,
+ boost::shared_array<const uint64_t> > ArrayVariant;
+
+ unsigned int mArrayPointerNumValues;
+ std::vector<unsigned int> mDimensions;
+ std::string mName;
+ unsigned int mTmpReserveSize;
+ ReadMode mReadMode;
+ shared_ptr<XdmfArrayReference> mReference;
+ ArrayVariant mArray;
+};
+
+#include "XdmfArray.tpp"
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define XDMF_ARRAY_READ_MODE_CONTROLLER 10
+#define XDMF_ARRAY_READ_MODE_REFERENCE 11
+
+// C wrappers go here
+
+struct XDMFARRAY; // Simply as a typedef to ensure correct typing
+typedef struct XDMFARRAY XDMFARRAY;
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfArrayNew();
+
+XDMFCORE_EXPORT void XdmfArrayClear(XDMFARRAY * array);
+
+XDMFCORE_EXPORT void XdmfArrayErase(XDMFARRAY * array, unsigned int index);
+
+XDMFCORE_EXPORT int XdmfArrayGetArrayType(XDMFARRAY * array, int * status);
+
+XDMFCORE_EXPORT unsigned int XdmfArrayGetCapacity(XDMFARRAY * array);
+
+XDMFCORE_EXPORT unsigned int * XdmfArrayGetDimensions(XDMFARRAY * array);
+
+XDMFCORE_EXPORT char * XdmfArrayGetDimensionsString(XDMFARRAY * array);
+
+XDMFCORE_EXPORT XDMFHEAVYDATACONTROLLER * XdmfArrayGetHeavyDataController(XDMFARRAY * array, unsigned int index);
+
+XDMFCORE_EXPORT int XdmfArrayGetReadMode(XDMFARRAY * array, int * status);
+
+XDMFCORE_EXPORT char * XdmfArrayGetName(XDMFARRAY * array);
+
+XDMFCORE_EXPORT unsigned int XdmfArrayGetNumberDimensions(XDMFARRAY * array);
+
+XDMFCORE_EXPORT unsigned int XdmfArrayGetNumberHeavyDataControllers(XDMFARRAY * array);
+
+XDMFCORE_EXPORT unsigned int XdmfArrayGetSize(XDMFARRAY * array);
+
+XDMFCORE_EXPORT XDMFARRAYREFERENCE * XdmfArrayGetReference(XDMFARRAY * array);
+
+XDMFCORE_EXPORT void * XdmfArrayGetValue(XDMFARRAY * array, unsigned int index, int arrayType, int * status);
+
+XDMFCORE_EXPORT void * XdmfArrayGetValues(XDMFARRAY * array, unsigned int startIndex, int arrayType, unsigned int numValues, unsigned int arrayStride, unsigned int valueStride, int * status);
+
+XDMFCORE_EXPORT void * XdmfArrayGetValuesInternal(XDMFARRAY * array);
+
+XDMFCORE_EXPORT char * XdmfArrayGetValuesString(XDMFARRAY * array);
+
+XDMFCORE_EXPORT void XdmfArrayInitialize(XDMFARRAY * array, int * dims, int numDims, int arrayType, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayInsertDataFromPointer(XDMFARRAY * array, void * values, int arrayType, unsigned int startIndex, unsigned int numVals, unsigned int arrayStride, unsigned int valueStride, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayInsertDataFromXdmfArray(XDMFARRAY * array, XDMFARRAY * valArray, int * arrayStarts, int * valueStarts, int * arrayCounts, int * valueCounts, int * arrayStrides, int * valueStrides, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayInsertHeavyDataController(XDMFARRAY * array, XDMFHEAVYDATACONTROLLER * controller, int passControl);
+
+XDMFCORE_EXPORT void XdmfArrayInsertValue(XDMFARRAY * array, unsigned int index, void * value, int arrayType, int * status);
+
+XDMFCORE_EXPORT int XdmfArrayIsInitialized(XDMFARRAY * array);
+
+XDMFCORE_EXPORT void XdmfArrayPushBack(XDMFARRAY * array, void * value, int arrayType, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayRead(XDMFARRAY * array, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayReadController(XDMFARRAY * array, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayReadReference(XDMFARRAY * array, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayRelease(XDMFARRAY * array);
+
+XDMFCORE_EXPORT void XdmfArrayRemoveHeavyDataController(XDMFARRAY * array, unsigned int index);
+
+XDMFCORE_EXPORT void XdmfArrayReserve(XDMFARRAY * array, int size);
+
+XDMFCORE_EXPORT void XdmfArrayResize(XDMFARRAY * array, int * dims, int numDims, int arrayType, int * status);
+
+XDMFCORE_EXPORT void XdmfArraySetReadMode(XDMFARRAY * array, int readMode, int * status);
+
+XDMFCORE_EXPORT void XdmfArraySetReference(XDMFARRAY * array, XDMFARRAYREFERENCE * reference, int passControl);
+
+XDMFCORE_EXPORT void XdmfArraySetName(XDMFARRAY * array, char * name, int * status);
+
+XDMFCORE_EXPORT void XdmfArraySetValuesInternal(XDMFARRAY * array, void * pointer, unsigned int numValues, int arrayType, int transferOwnership, int * status);
+
+XDMFCORE_EXPORT void XdmfArraySwapWithXdmfArray(XDMFARRAY * array, XDMFARRAY * swapArray);
+
+XDMFCORE_EXPORT void XdmfArraySwapWithArray(XDMFARRAY * array, void ** pointer, int numValues, int arrayType, int * status);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfArray, XDMFARRAY, XDMFCORE)
+
+
+#define XDMF_ARRAY_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT void ClassName##Clear( CClassName * array); \
+Level##_EXPORT void ClassName##Erase( CClassName * array, unsigned int index); \
+Level##_EXPORT int ClassName##GetArrayType( CClassName * array, int * status); \
+Level##_EXPORT unsigned int ClassName##GetCapacity( CClassName * array); \
+Level##_EXPORT unsigned int * ClassName##GetDimensions( CClassName * array); \
+Level##_EXPORT char * ClassName##GetDimensionsString( CClassName * array); \
+Level##_EXPORT XDMFHEAVYDATACONTROLLER * ClassName##GetHeavyDataController( CClassName * array, unsigned int index); \
+Level##_EXPORT int ClassName##GetReadMode( CClassName * array, int * status); \
+Level##_EXPORT char * ClassName##GetName( CClassName * array); \
+Level##_EXPORT unsigned int ClassName##GetNumberDimensions( CClassName * array); \
+Level##_EXPORT unsigned int ClassName##GetNumberHeavyDataControllers( CClassName * array); \
+Level##_EXPORT unsigned int ClassName##GetSize( CClassName * array); \
+Level##_EXPORT XDMFARRAYREFERENCE * ClassName##GetReference( CClassName * array); \
+Level##_EXPORT void * ClassName##GetValue( CClassName * array, \
+ unsigned int index, \
+ int arrayType, \
+ int * status); \
+Level##_EXPORT void * ClassName##GetValues( CClassName * array, \
+ unsigned int startIndex, \
+ int arrayType, \
+ unsigned int numValues, \
+ unsigned int arrayStride, \
+ unsigned int valueStride, \
+ int * status); \
+Level##_EXPORT void * ClassName##GetValuesInternal( CClassName * array); \
+Level##_EXPORT char * ClassName##GetValuesString( CClassName * array); \
+Level##_EXPORT void ClassName##Initialize( CClassName * array, \
+ int * dims, \
+ int numDims, \
+ int arrayType, \
+ int * status); \
+Level##_EXPORT void ClassName##InsertDataFromPointer( CClassName * array, \
+ void * values, \
+ int arrayType, \
+ unsigned int startIndex, \
+ unsigned int numVals, \
+ unsigned int arrayStride, \
+ unsigned int valueStride, \
+ int * status); \
+Level##_EXPORT void ClassName##InsertDataFromXdmfArray( CClassName * array, \
+ XDMFARRAY * valArray, \
+ int * arrayStarts, \
+ int * valueStarts, \
+ int * arrayCounts, \
+ int * valueCounts, \
+ int * arrayStrides, \
+ int * valueStrides, \
+ int * status); \
+Level##_EXPORT void ClassName##InsertHeavyDataController( CClassName * array, \
+ XDMFHEAVYDATACONTROLLER * controller, \
+ int passControl); \
+Level##_EXPORT void ClassName##InsertValue( CClassName * array, \
+ unsigned int index, \
+ void * value, \
+ int arrayType, \
+ int * status); \
+Level##_EXPORT int ClassName##IsInitialized( CClassName * array); \
+Level##_EXPORT void ClassName##PushBack( CClassName * array, \
+ void * value, \
+ int arrayType, \
+ int * status); \
+Level##_EXPORT void ClassName##Read( CClassName * array, int * status); \
+Level##_EXPORT void ClassName##ReadController( CClassName * array, int * status); \
+Level##_EXPORT void ClassName##ReadReference( CClassName * array, int * status); \
+Level##_EXPORT void ClassName##Release( CClassName * array); \
+Level##_EXPORT void ClassName##RemoveHeavyDataController( CClassName * array, unsigned int index); \
+Level##_EXPORT void ClassName##Reserve( CClassName * array, int size); \
+Level##_EXPORT void ClassName##Resize( CClassName * array, \
+ int * dims, \
+ int numDims, \
+ int arrayType, \
+ int * status); \
+Level##_EXPORT void ClassName##SetReadMode( CClassName * array, int readMode, int * status); \
+Level##_EXPORT void ClassName##SetReference( CClassName * array, XDMFARRAYREFERENCE * reference, int passControl); \
+Level##_EXPORT void ClassName##SetName( CClassName * array, char * name, int * status); \
+Level##_EXPORT void ClassName##SetValuesInternal( CClassName * array, \
+ void * pointer, \
+ unsigned int numValues, \
+ int arrayType, \
+ int transferOwnership, \
+ int * status); \
+Level##_EXPORT void ClassName##SwapWithXdmfArray( CClassName * array, XDMFARRAY * swapArray); \
+Level##_EXPORT void ClassName##SwapWithArray( CClassName * array, \
+ void ** pointer, \
+ int numValues, \
+ int arrayType, \
+ int * status);
+
+
+#define XDMF_ARRAY_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+void ClassName##Clear( CClassName * array) \
+{ \
+ XdmfArrayClear((XDMFARRAY *)((void *)array)); \
+} \
+ \
+void ClassName##Erase( CClassName * array, unsigned int index) \
+{ \
+ XdmfArrayErase((XDMFARRAY *)((void *)array), index); \
+} \
+ \
+int ClassName##GetArrayType( CClassName * array, int * status) \
+{ \
+ return XdmfArrayGetArrayType((XDMFARRAY *)((void *)array), status); \
+} \
+ \
+unsigned int ClassName##GetCapacity( CClassName * array) \
+{ \
+ return XdmfArrayGetCapacity((XDMFARRAY *)((void *)array)); \
+} \
+ \
+unsigned int * \
+ClassName##GetDimensions( CClassName * array) \
+{ \
+ return XdmfArrayGetDimensions((XDMFARRAY *)((void *)array)); \
+} \
+ \
+char * \
+ClassName##GetDimensionsString( CClassName * array) \
+{ \
+ return XdmfArrayGetDimensionsString((XDMFARRAY *)((void *)array)); \
+} \
+ \
+XDMFHEAVYDATACONTROLLER * \
+ClassName##GetHeavyDataController( CClassName * array, unsigned int index) \
+{ \
+ return XdmfArrayGetHeavyDataController((XDMFARRAY *)((void *)array), index); \
+} \
+ \
+char * \
+ClassName##GetName( CClassName * array) \
+{ \
+ return XdmfArrayGetName((XDMFARRAY *)((void *)array)); \
+} \
+ \
+unsigned int \
+ClassName##GetNumberDimensions( CClassName * array) \
+{ \
+ return XdmfArrayGetNumberDimensions((XDMFARRAY *)((void *)array)); \
+} \
+ \
+unsigned int \
+ClassName##GetNumberHeavyDataControllers( CClassName * array) \
+{ \
+ return XdmfArrayGetNumberHeavyDataControllers((XDMFARRAY *)((void *)array)); \
+} \
+ \
+unsigned int \
+ClassName##GetSize( CClassName * array) \
+{ \
+ return XdmfArrayGetSize((XDMFARRAY *)((void *)array)); \
+} \
+ \
+int \
+ClassName##GetReadMode( CClassName * array, int * status) \
+{ \
+ return XdmfArrayGetReadMode((XDMFARRAY *)((void *)array), status); \
+} \
+ \
+XDMFARRAYREFERENCE * \
+ClassName##GetReference( CClassName * array) \
+{ \
+ return XdmfArrayGetReference((XDMFARRAY *)((void *)array)); \
+} \
+ \
+void * \
+ClassName##GetValue( CClassName * array, unsigned int index, int arrayType, int * status) \
+{ \
+ return XdmfArrayGetValue((XDMFARRAY *)((void *)array), index, arrayType, status); \
+} \
+ \
+void * \
+ClassName##GetValues( CClassName * array, \
+ unsigned int startIndex, \
+ int arrayType, \
+ unsigned int numValues, \
+ unsigned int arrayStride, \
+ unsigned int valueStride, \
+ int * status) \
+{ \
+ return XdmfArrayGetValues((XDMFARRAY *)((void *)array), \
+ startIndex, \
+ arrayType, \
+ numValues, \
+ arrayStride, \
+ valueStride, \
+ status); \
+} \
+ \
+void * \
+ClassName##GetValuesInternal( CClassName * array) \
+{ \
+ return XdmfArrayGetValuesInternal((XDMFARRAY *)((void *)array)); \
+} \
+ \
+char * \
+ClassName##GetValuesString( CClassName * array) \
+{ \
+ return XdmfArrayGetValuesString((XDMFARRAY *)((void *)array)); \
+} \
+ \
+void \
+ClassName##Initialize( CClassName * array, int * dims, int numDims, int arrayType, int * status) \
+{ \
+ XdmfArrayInitialize((XDMFARRAY *)((void *)array), dims, numDims, arrayType, status); \
+} \
+ \
+void \
+ClassName##InsertDataFromPointer( CClassName * array, \
+ void * values, \
+ int arrayType, \
+ unsigned int startIndex, \
+ unsigned int numVals, \
+ unsigned int arrayStride, \
+ unsigned int valueStride, \
+ int * status) \
+{ \
+ XdmfArrayInsertDataFromPointer((XDMFARRAY *)((void *)array), \
+ values, \
+ arrayType, \
+ startIndex, \
+ numVals, \
+ arrayStride, \
+ valueStride, \
+ status); \
+} \
+ \
+void ClassName##InsertDataFromXdmfArray( CClassName * array, \
+ XDMFARRAY * valArray, \
+ int * arrayStarts, \
+ int * valueStarts, \
+ int * arrayCounts, \
+ int * valueCounts, \
+ int * arrayStrides, \
+ int * valueStrides, \
+ int * status) \
+{ \
+ XdmfArrayInsertDataFromXdmfArray((XDMFARRAY *)((void *)array), \
+ valArray, \
+ arrayStarts, \
+ valueStarts, \
+ arrayCounts, \
+ valueCounts, \
+ arrayStrides, \
+ valueStrides, \
+ status); \
+} \
+ \
+void \
+ClassName##InsertHeavyDataController( CClassName * array, XDMFHEAVYDATACONTROLLER * controller, int passControl) \
+{ \
+ XdmfArrayInsertHeavyDataController((XDMFARRAY *)((void *)array), controller, passControl); \
+} \
+ \
+void \
+ClassName##InsertValue( CClassName * array, \
+ unsigned int index, \
+ void * value, \
+ int arrayType, \
+ int * status) \
+{ \
+ XdmfArrayInsertValue((XDMFARRAY *)((void *)array), index, value, arrayType, status); \
+} \
+ \
+int \
+ClassName##IsInitialized( CClassName * array) \
+{ \
+ return XdmfArrayIsInitialized((XDMFARRAY *)((void *)array)); \
+} \
+ \
+void \
+ClassName##PushBack( CClassName * array, void * value, int arrayType, int * status) \
+{ \
+ XdmfArrayPushBack((XDMFARRAY *)((void *)array), value, arrayType, status); \
+} \
+ \
+void \
+ClassName##Read( CClassName * array, int * status) \
+{ \
+ XdmfArrayRead((XDMFARRAY *)((void *)array), status); \
+} \
+ \
+void \
+ClassName##ReadController( CClassName * array, int * status) \
+{ \
+ XdmfArrayReadController((XDMFARRAY *)((void *)array), status); \
+} \
+ \
+void \
+ClassName##ReadReference( CClassName * array, int * status) \
+{ \
+ XdmfArrayReadReference((XDMFARRAY *)((void *)array), status); \
+} \
+ \
+void \
+ClassName##Release( CClassName * array) \
+{ \
+ XdmfArrayRelease((XDMFARRAY *)((void *)array)); \
+} \
+ \
+void \
+ClassName##RemoveHeavyDataController( CClassName * array, unsigned int index) \
+{ \
+ XdmfArrayRemoveHeavyDataController((XDMFARRAY *)((void *)array), index); \
+} \
+ \
+void \
+ClassName##Reserve( CClassName * array, int size) \
+{ \
+ XdmfArrayReserve((XDMFARRAY *)((void *)array), size); \
+} \
+ \
+void \
+ClassName##Resize( CClassName * array, int * dims, int numDims, int arrayType, int * status) \
+{ \
+ XdmfArrayResize((XDMFARRAY *)((void *)array), dims, numDims, arrayType, status); \
+} \
+ \
+void \
+ClassName##SetReadMode( CClassName * array, int readMode, int * status) \
+{ \
+ XdmfArraySetReadMode((XDMFARRAY *)((void *)array), readMode, status); \
+} \
+ \
+void \
+ClassName##SetReference( CClassName * array, XDMFARRAYREFERENCE * reference, int passControl) \
+{ \
+ XdmfArraySetReference((XDMFARRAY *)((void *)array), reference, passControl); \
+} \
+ \
+void \
+ClassName##SetName( CClassName * array, char * name, int * status) \
+{ \
+ XdmfArraySetName((XDMFARRAY *)((void *)array), name, status); \
+} \
+ \
+void \
+ClassName##SetValuesInternal( CClassName * array, \
+ void * pointer, \
+ unsigned int numValues, \
+ int arrayType, \
+ int transferOwnership, \
+ int * status) \
+{ \
+ XdmfArraySetValuesInternal((XDMFARRAY *)((void *)array), \
+ pointer, \
+ numValues, \
+ arrayType, \
+ transferOwnership, \
+ status); \
+} \
+ \
+void \
+ClassName##SwapWithXdmfArray( CClassName * array, XDMFARRAY * swapArray) \
+{ \
+ XdmfArraySwapWithXdmfArray((XDMFARRAY *)((void *)array), swapArray); \
+} \
+ \
+void \
+ClassName##SwapWithArray( CClassName * array, \
+ void ** pointer, \
+ int numValues, \
+ int arrayType, \
+ int * status) \
+{ \
+ XdmfArraySwapWithArray((XDMFARRAY *)((void *)array), pointer, numValues, arrayType, status); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFARRAY_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* Xdmf */
+/* Extensible Data Model and Format */
+/* */
+/* Id : XdmfArray.tpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <functional>
+#include <numeric>
+#include <sstream>
+#include "XdmfArray.hpp"
+
+template <typename T>
+class XdmfArray::GetValue : public boost::static_visitor<T> {
+public:
+
+ GetValue(const unsigned int index) :
+ mIndex(index)
+ {
+ }
+
+ T
+ operator()(const boost::blank &) const
+ {
+ return 0;
+ }
+
+ T
+ operator()(const shared_ptr<std::vector<std::string> > & array) const
+ {
+ return (T)atof(array->operator[](mIndex).c_str());
+ }
+
+ template<typename U>
+ T
+ operator()(const shared_ptr<std::vector<U> > & array) const
+ {
+ return (T)array->operator[](mIndex);
+ }
+
+ template<typename U>
+ T
+ operator()(const boost::shared_array<const U> & array) const
+ {
+ return (T)array[mIndex];
+ }
+
+private:
+
+ const unsigned int mIndex;
+};
+
+template <>
+class XdmfArray::GetValue<std::string> :
+ public boost::static_visitor<std::string> {
+public:
+
+ GetValue(const unsigned int index) :
+ mIndex(index)
+ {
+ }
+
+ std::string
+ operator()(const boost::blank &) const
+ {
+ return "";
+ }
+
+ std::string
+ operator()(const shared_ptr<std::vector<std::string> > & array) const
+ {
+ return array->operator[](mIndex);
+ }
+
+ template<typename U>
+ std::string
+ operator()(const shared_ptr<std::vector<U> > & array) const
+ {
+ std::stringstream value;
+ value << array->operator[](mIndex);
+ return value.str();
+ }
+
+ std::string
+ operator()(const boost::shared_array<const std::string> & array) const
+ {
+ return array[mIndex];
+ }
+
+ template<typename U>
+ std::string
+ operator()(const boost::shared_array<const U> & array) const
+ {
+ std::stringstream value;
+ value << array[mIndex];
+ return value.str();
+ }
+
+private:
+
+ const unsigned int mIndex;
+};
+
+template <typename T>
+class XdmfArray::GetValues : public boost::static_visitor<void> {
+public:
+
+ GetValues(const unsigned int startIndex,
+ T * valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride) :
+ mStartIndex(startIndex),
+ mValuesPointer(valuesPointer),
+ mNumValues(numValues),
+ mArrayStride(arrayStride),
+ mValuesStride(valuesStride)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ return;
+ }
+
+ void
+ operator()(const shared_ptr<std::vector<std::string> > & array) const
+ {
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ mValuesPointer[i*mValuesStride] =
+ (T)atof(array->operator[](mStartIndex + i*mArrayStride).c_str());
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(const shared_ptr<std::vector<U> > & array) const
+ {
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ mValuesPointer[i*mValuesStride] =
+ (T)array->operator[](mStartIndex + i*mArrayStride);
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(const boost::shared_array<const U> & array) const
+ {
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ mValuesPointer[i*mValuesStride] = (T)array[mStartIndex + i*mArrayStride];
+ }
+ }
+
+private:
+
+ const unsigned int mStartIndex;
+ T * mValuesPointer;
+ const unsigned int mNumValues;
+ const unsigned int mArrayStride;
+ const unsigned int mValuesStride;
+};
+
+template <>
+class XdmfArray::GetValues<std::string> : public boost::static_visitor<void> {
+public:
+
+ GetValues(const unsigned int startIndex,
+ std::string * valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride) :
+ mStartIndex(startIndex),
+ mValuesPointer(valuesPointer),
+ mNumValues(numValues),
+ mArrayStride(arrayStride),
+ mValuesStride(valuesStride)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ return;
+ }
+
+ template<typename U>
+ void
+ operator()(const shared_ptr<std::vector<U> > & array) const
+ {
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ std::stringstream value;
+ value << array->operator[](mStartIndex + i*mArrayStride);
+ mValuesPointer[i*mValuesStride] = value.str();
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(const boost::shared_array<const U> & array) const
+ {
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ std::stringstream value;
+ value << array[mStartIndex + i*mArrayStride];
+ mValuesPointer[i*mValuesStride] = value.str();
+ }
+ }
+
+private:
+
+ const unsigned int mStartIndex;
+ std::string * mValuesPointer;
+ const unsigned int mNumValues;
+ const unsigned int mArrayStride;
+ const unsigned int mValuesStride;
+};
+
+template <typename T>
+class XdmfArray::Insert : public boost::static_visitor<void> {
+public:
+
+ Insert(XdmfArray * const array,
+ const unsigned int startIndex,
+ const T * const valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride,
+ std::vector<unsigned int> & dimensions) :
+ mArray(array),
+ mStartIndex(startIndex),
+ mValuesPointer(valuesPointer),
+ mNumValues(numValues),
+ mArrayStride(arrayStride),
+ mValuesStride(valuesStride),
+ mDimensions(dimensions)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ mArray->initialize<T>();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ void
+ operator()(shared_ptr<std::vector<std::string> > & array) const
+ {
+ unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
+ if(array->size() < size) {
+ array->resize(size);
+ mDimensions.clear();
+ }
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ std::stringstream value;
+ value << mValuesPointer[i*mValuesStride];
+ array->operator[](mStartIndex + i*mArrayStride) = value.str();
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(shared_ptr<std::vector<U> > & array) const
+ {
+ unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
+ if(array->size() < size) {
+ array->resize(size);
+ mDimensions.clear();
+ }
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ array->operator[](mStartIndex + i*mArrayStride) =
+ (U)mValuesPointer[i*mValuesStride];
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(boost::shared_array<const U> &) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * const mArray;
+ const unsigned int mStartIndex;
+ const T * const mValuesPointer;
+ const unsigned int mNumValues;
+ const unsigned int mArrayStride;
+ const unsigned int mValuesStride;
+ std::vector<unsigned int> & mDimensions;
+};
+
+template <>
+class XdmfArray::Insert<std::string> : public boost::static_visitor<void> {
+public:
+
+ Insert(XdmfArray * const array,
+ const unsigned int startIndex,
+ const std::string * const valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride,
+ std::vector<unsigned int> & dimensions) :
+ mArray(array),
+ mStartIndex(startIndex),
+ mValuesPointer(valuesPointer),
+ mNumValues(numValues),
+ mArrayStride(arrayStride),
+ mValuesStride(valuesStride),
+ mDimensions(dimensions)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ mArray->initialize<std::string>();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ void
+ operator()(shared_ptr<std::vector<std::string> > & array) const
+ {
+ unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
+ if(array->size() < size) {
+ array->resize(size);
+ mDimensions.clear();
+ }
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ array->operator[](mStartIndex + i*mArrayStride) =
+ mValuesPointer[i*mValuesStride].c_str();
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(shared_ptr<std::vector<U> > & array) const
+ {
+ unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
+ if(array->size() < size) {
+ array->resize(size);
+ mDimensions.clear();
+ }
+ for(unsigned int i=0; i<mNumValues; ++i) {
+ array->operator[](mStartIndex + i*mArrayStride) =
+ (U)atof(mValuesPointer[i*mValuesStride].c_str());
+ }
+ }
+
+ template<typename U>
+ void
+ operator()(boost::shared_array<const U> &) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * const mArray;
+ const unsigned int mStartIndex;
+ const std::string * const mValuesPointer;
+ const unsigned int mNumValues;
+ const unsigned int mArrayStride;
+ const unsigned int mValuesStride;
+ std::vector<unsigned int> & mDimensions;
+};
+
+template <typename T>
+class XdmfArray::PushBack : public boost::static_visitor<void> {
+public:
+
+ PushBack(const T & val,
+ XdmfArray * const array) :
+ mVal(val),
+ mArray(array)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ mArray->initialize<T>();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ void
+ operator()(shared_ptr<std::vector<std::string> > & array) const
+ {
+ std::stringstream value;
+ value << mVal;
+ array->push_back(value.str());
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(shared_ptr<std::vector<U> > & array) const
+ {
+ array->push_back((U)mVal);
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(const boost::shared_array<const U> &) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ const T & mVal;
+ XdmfArray * const mArray;
+};
+
+template <>
+class XdmfArray::PushBack<std::string> : public boost::static_visitor<void> {
+public:
+
+ PushBack(const std::string & val,
+ XdmfArray * const array) :
+ mVal(val),
+ mArray(array)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ mArray->initialize<std::string>();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ void
+ operator()(shared_ptr<std::vector<std::string> > & array) const
+ {
+ array->push_back(mVal);
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(shared_ptr<std::vector<U> > & array) const
+ {
+ array->push_back((U)atof(mVal.c_str()));
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(const boost::shared_array<const U> &) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ const std::string & mVal;
+ XdmfArray * const mArray;
+};
+
+template <typename T>
+class XdmfArray::Resize : public boost::static_visitor<void> {
+public:
+
+ Resize(XdmfArray * const array,
+ const unsigned int numValues,
+ const T & val) :
+ mArray(array),
+ mNumValues(numValues),
+ mVal(val)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ mArray->initialize<T>();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ void
+ operator()(shared_ptr<std::vector<std::string> > & array) const
+ {
+ std::stringstream value;
+ value << mVal;
+ array->resize(mNumValues, value.str());
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(shared_ptr<std::vector<U> > & array) const
+ {
+ array->resize(mNumValues, (U)mVal);
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(const boost::shared_array<const U> &) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * mArray;
+ const unsigned int mNumValues;
+ const T & mVal;
+};
+
+template <>
+class XdmfArray::Resize<std::string> : public boost::static_visitor<void> {
+public:
+
+ Resize(XdmfArray * const array,
+ const unsigned int numValues,
+ const std::string & val) :
+ mArray(array),
+ mNumValues(numValues),
+ mVal(val)
+ {
+ }
+
+ void
+ operator()(const boost::blank &) const
+ {
+ mArray->initialize<std::string>();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+ void
+ operator()(shared_ptr<std::vector<std::string> > & array) const
+ {
+ array->resize(mNumValues, mVal);
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(shared_ptr<std::vector<U> > & array) const
+ {
+ array->resize(mNumValues, (U)atof(mVal.c_str()));
+ mArray->mDimensions.clear();
+ }
+
+ template<typename U>
+ void
+ operator()(const boost::shared_array<const U> &) const
+ {
+ mArray->internalizeArrayPointer();
+ boost::apply_visitor(*this,
+ mArray->mArray);
+ }
+
+private:
+
+ XdmfArray * mArray;
+ const unsigned int mNumValues;
+ const std::string & mVal;
+};
+
+struct XdmfArray::NullDeleter
+{
+ void
+ operator()(void const *) const
+ {
+ }
+};
+
+template <typename T>
+T
+XdmfArray::getValue(const unsigned int index) const
+{
+ return boost::apply_visitor(GetValue<T>(index),
+ mArray);
+}
+
+template <typename T>
+void
+XdmfArray::getValues(const unsigned int startIndex,
+ T * const valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride) const
+{
+ boost::apply_visitor(GetValues<T>(startIndex,
+ valuesPointer,
+ numValues,
+ arrayStride,
+ valuesStride),
+ mArray);
+}
+
+template <typename T>
+shared_ptr<std::vector<T> >
+XdmfArray::getValuesInternal()
+{
+ this->internalizeArrayPointer();
+ try {
+ shared_ptr<std::vector<T> > currArray =
+ boost::get<shared_ptr<std::vector<T> > >(mArray);
+ return currArray;
+ }
+ catch(const boost::bad_get & exception) {
+ return shared_ptr<std::vector<T> >();
+ }
+}
+
+template <typename T>
+shared_ptr<std::vector<T> >
+XdmfArray::initialize(const unsigned int size)
+{
+ // Set type of variant to type of pointer
+ shared_ptr<std::vector<T> > newArray(new std::vector<T>(size));
+ if(mTmpReserveSize > 0) {
+ newArray->reserve(mTmpReserveSize);
+ mTmpReserveSize = 0;
+ }
+ mArray = newArray;
+ this->setIsChanged(true);
+ return newArray;
+}
+
+template <typename T>
+shared_ptr<std::vector<T> >
+XdmfArray::initialize(const std::vector<unsigned int> & dimensions)
+{
+ mDimensions = dimensions;
+ const unsigned int size = static_cast<unsigned int>(
+ std::accumulate(dimensions.begin(), dimensions.end(), 1,
+ std::multiplies<unsigned int>()));
+ return this->initialize<T>(size);
+}
+
+template<typename T>
+void
+XdmfArray::insert(const unsigned int index,
+ const T & value)
+{
+ boost::apply_visitor(Insert<T>(this,
+ index,
+ &value,
+ 1,
+ 0,
+ 0,
+ mDimensions),
+ mArray);
+}
+
+template <typename T>
+void
+XdmfArray::insert(const unsigned int startIndex,
+ const T * const valuesPointer,
+ const unsigned int numValues,
+ const unsigned int arrayStride,
+ const unsigned int valuesStride)
+{
+ boost::apply_visitor(Insert<T>(this,
+ startIndex,
+ valuesPointer,
+ numValues,
+ arrayStride,
+ valuesStride,
+ mDimensions),
+ mArray);
+ this->setIsChanged(true);
+}
+
+template <typename T>
+void
+XdmfArray::pushBack(const T & value)
+{
+ this->setIsChanged(true);
+ return boost::apply_visitor(PushBack<T>(value,
+ this),
+ mArray);
+
+}
+
+template<typename T>
+void
+XdmfArray::resize(const unsigned int numValues,
+ const T & value)
+{
+ this->setIsChanged(true);
+ return boost::apply_visitor(Resize<T>(this,
+ numValues,
+ value),
+ mArray);
+
+}
+
+template<typename T>
+void
+XdmfArray::resize(const std::vector<unsigned int> & dimensions,
+ const T & value)
+{
+ const unsigned int size = static_cast<unsigned int>(std::accumulate(dimensions.begin(), dimensions.end(), 1,
+ std::multiplies<unsigned int>()));
+ this->resize(size, value);
+ mDimensions = dimensions;
+ this->setIsChanged(true);
+}
+
+template <typename T>
+void
+XdmfArray::setValuesInternal(const T * const arrayPointer,
+ const unsigned int numValues,
+ const bool transferOwnership)
+{
+ // Remove contents of internal array.
+ if(transferOwnership) {
+ const boost::shared_array<const T> newArrayPointer(arrayPointer);
+ mArray = newArrayPointer;
+ }
+ else {
+ const boost::shared_array<const T> newArrayPointer(arrayPointer,
+ NullDeleter());
+ mArray = newArrayPointer;
+ }
+ mArrayPointerNumValues = numValues;
+ this->setIsChanged(true);
+}
+
+template <typename T>
+void
+XdmfArray::setValuesInternal(std::vector<T> & array,
+ const bool transferOwnership)
+{
+ if(transferOwnership) {
+ shared_ptr<std::vector<T> > newArray(&array);
+ mArray = newArray;
+ }
+ else {
+ shared_ptr<std::vector<T> > newArray(&array, NullDeleter());
+ mArray = newArray;
+ }
+ this->setIsChanged(true);
+}
+
+template <typename T>
+void
+XdmfArray::setValuesInternal(const shared_ptr<std::vector<T> > array)
+{
+ mArray = array;
+ this->setIsChanged(true);
+}
+
+template <typename T>
+bool
+XdmfArray::swap(std::vector<T> & array)
+{
+ this->internalizeArrayPointer();
+ if(!this->isInitialized()) {
+ this->initialize<T>();
+ }
+ try {
+ shared_ptr<std::vector<T> > currArray =
+ boost::get<shared_ptr<std::vector<T> > >(mArray);
+ currArray->swap(array);
+ return true;
+ }
+ catch(const boost::bad_get & exception) {
+ return false;
+ }
+ this->setIsChanged(true);
+}
+
+template <typename T>
+bool
+XdmfArray::swap(const shared_ptr<std::vector<T> > array)
+{
+ return this->swap(*array.get());
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfFunction.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfArrayReference.hpp"
+#include <stack>
+#include <math.h>
+#include <boost/assign.hpp>
+#include "XdmfError.hpp"
+
+XdmfArrayReference::XdmfArrayReference():
+ mConstructedType("")
+{
+}
+
+XdmfArrayReference::XdmfArrayReference(XdmfArrayReference & refReference) :
+ XdmfItem(refReference),
+ mConstructedType(refReference.mConstructedType),
+ mConstructedProperties(refReference.mConstructedProperties)
+{
+}
+
+XdmfArrayReference::~XdmfArrayReference()
+{
+}
+
+std::map<std::string, std::string>
+XdmfArrayReference::getConstructedProperties()
+{
+ return mConstructedProperties;
+}
+
+std::string
+XdmfArrayReference::getConstructedType() const
+{
+ if (mConstructedType.c_str() != NULL) {
+ return mConstructedType;
+ }
+ else {
+ return "";
+ }
+}
+
+std::map<std::string, std::string>
+XdmfArrayReference::getItemProperties() const
+{
+ std::map<std::string, std::string> referenceProperties;
+
+ referenceProperties["ConstructedType"] = mConstructedType;
+
+ for (std::map<std::string, std::string>::const_iterator constructedIt = mConstructedProperties.begin();
+ constructedIt != mConstructedProperties.end();
+ ++constructedIt) {
+ referenceProperties[constructedIt->first] = constructedIt->second;
+ }
+
+ // An array is missing a lot of data if not read first
+ if (mConstructedType.compare(XdmfArray::ItemTag) == 0) {
+ shared_ptr<XdmfArray> resultArray = this->read();
+ shared_ptr<const XdmfArrayType> resultArrayType = resultArray->getArrayType();
+ std::map<std::string, std::string> arrayTypeProperties;
+ resultArrayType->getProperties(arrayTypeProperties);
+ for (std::map<std::string, std::string>::const_iterator arrayTypeIt = arrayTypeProperties.begin();
+ arrayTypeIt != arrayTypeProperties.end();
+ ++arrayTypeIt) {
+ referenceProperties[arrayTypeIt->first] = arrayTypeIt->second;
+ }
+ referenceProperties["Format"] = "XML";
+ referenceProperties["Dimensions"] = resultArray->getDimensionsString();
+ }
+
+ return referenceProperties;
+}
+
+void
+XdmfArrayReference::setConstructedProperties(std::map<std::string, std::string> newProperties)
+{
+ mConstructedProperties = newProperties;
+ this->setIsChanged(true);
+}
+
+void
+XdmfArrayReference::setConstructedType(std::string newType)
+{
+ mConstructedType = newType;
+ this->setIsChanged(true);
+}
+
+// C Wrappers
+
+char * XdmfArrayReferenceGetConstructedType(XDMFARRAYREFERENCE * arrayReference)
+{
+ try
+ {
+ char * returnPointer = strdup((*((XdmfArrayReference *)arrayReference)).getConstructedType().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup((*((XdmfArrayReference *)arrayReference)).getConstructedType().c_str());
+ return returnPointer;
+ }
+}
+
+void * XdmfArrayReferenceRead(XDMFARRAYREFERENCE * arrayReference, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ shared_ptr<XdmfArray> returnItem = ((XdmfArrayReference *)arrayReference)->read();
+ return new XdmfArray(*returnItem.get());
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfArray> returnItem = ((XdmfArrayReference *)arrayReference)->read();
+ return new XdmfArray(*returnItem.get());
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void XdmfArrayReferenceSetConstructedProperties(XDMFARRAYREFERENCE * arrayReference, void * referenceobject)
+{
+ ((XdmfArrayReference *)arrayReference)->setConstructedProperties(((XdmfItem *)referenceobject)->getItemProperties());
+}
+
+void XdmfArrayReferenceSetConstructedType(XDMFARRAYREFERENCE * arrayReference, char * newType)
+{
+ ((XdmfArrayReference *)arrayReference)->setConstructedType(newType);
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfArrayReference, XDMFARRAYREFERENCE)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfArrayReference.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFARRAYREFERENCE_HPP_
+#define XDMFARRAYREFERENCE_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfItem.hpp"
+
+#ifdef __cplusplus
+
+class XdmfArray;
+
+/**
+ * @brief Serves as a link between an array and one or more arrays containing data it pulls from.
+ *
+ * The Array Reference class provides the basic framework for the writing and
+ * reading of the Function and Subset classes by allowing properties and tags
+ * to be migrated to them.
+ */
+class XDMFCORE_EXPORT XdmfArrayReference : public XdmfItem {
+
+public:
+
+ virtual ~XdmfArrayReference();
+
+ LOKI_DEFINE_VISITABLE(XdmfArrayReference, XdmfItem)
+
+ /**
+ * Gets the properties of the array that the reference will generate when read from file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#setConstructedProperties
+ * @until //#setConstructedProperties
+ * @skipline //#getConstructedProperties
+ * @until //#getConstructedProperties
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//setConstructedProperties
+ * @until #//setConstructedProperties
+ * @skipline #//getConstructedProperties
+ * @until #//getConstructedProperties
+ *
+ * @return The properties of the array to be generated
+ */
+ std::map<std::string, std::string> getConstructedProperties();
+
+ /**
+ * Gets the type of array that the reference will generate when read from file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#setConstructedType
+ * @until //#setConstructedType
+ * @skipline //#getConstructedType
+ * @until //#getConstructedType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//setConstructedType
+ * @until #//setConstructedType
+ * @skipline #//getConstructedType
+ * @until #//getConstructedType
+ *
+ * @return The tag of the type to be generated
+ */
+ std::string getConstructedType() const;
+
+ virtual std::map<std::string, std::string> getItemProperties() const;
+
+ /**
+ * Parses the reference and generates an array containing the values that
+ * the reference produces.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//read
+ * @until #//read
+ *
+ * @return The array generated by the reference
+ */
+ virtual shared_ptr<XdmfArray> read() const = 0;
+
+ /**
+ * Sets the properties of array that the reference will generate when read from file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#setConstructedProperties
+ * @until //#setConstructedProperties
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//setConstructedProperties
+ * @until #//setConstructedProperties
+ *
+ * @param newProperties The properties of the array to be generated
+ */
+ void
+ setConstructedProperties(std::map<std::string, std::string> newProperties);
+
+ /**
+ * Sets the type of array that the reference will generate when read from file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#setConstructedType
+ * @until //#setConstructedType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//setConstructedType
+ * @until #//setConstructedType
+ *
+ * @param newType The tag of the type to be generated
+ */
+ void setConstructedType(std::string newType);
+
+ XdmfArrayReference(XdmfArrayReference &);
+
+protected:
+
+ XdmfArrayReference();
+
+ std::string mConstructedType;
+ std::map<std::string, std::string> mConstructedProperties;
+
+private:
+
+ XdmfArrayReference(const XdmfArrayReference &); // Not implemented.
+ void operator=(const XdmfArrayReference &); // Not implemented.
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFARRAYREFERENCE; // Simply as a typedef to ensure correct typing
+typedef struct XDMFARRAYREFERENCE XDMFARRAYREFERENCE;
+
+XDMFCORE_EXPORT char * XdmfArrayReferenceGetConstructedType(XDMFARRAYREFERENCE * arrayReference);
+
+XDMFCORE_EXPORT void * XdmfArrayReferenceRead(XDMFARRAYREFERENCE * arrayReference, int * status);
+
+XDMFCORE_EXPORT void XdmfArrayReferenceSetConstructedProperties(XDMFARRAYREFERENCE * arrayReference, void * referenceobject);
+
+XDMFCORE_EXPORT void XdmfArrayReferenceSetConstructedType(XDMFARRAYREFERENCE * arrayReference, char * newType);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfArrayReference, XDMFARRAYREFERENCE, XDMFCORE)
+
+#define XDMF_ARRAYREFERENCE_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT char * ClassName##GetConstructedType( CClassName * arrayReference); \
+Level##_EXPORT void * ClassName##Read( CClassName * arrayReference, int * status); \
+Level##_EXPORT void ClassName##SetConstructedProperties( CClassName * arrayReference, void * referenceobject); \
+Level##_EXPORT void ClassName##SetConstructedType( CClassName * arrayReference, char * newType);
+
+
+
+#define XDMF_ARRAYREFERENCE_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+ \
+char * ClassName##GetConstructedType(CClassName * arrayReference) \
+{ \
+ return XdmfArrayReferenceGetConstructedType((XDMFARRAYREFERENCE *)((void *)arrayReference)); \
+} \
+ \
+void * ClassName##Read(CClassName * arrayReference, int * status) \
+{ \
+ return XdmfArrayReferenceRead((XDMFARRAYREFERENCE *)((void *)arrayReference), status); \
+} \
+ \
+void ClassName##SetConstructedProperties(CClassName * arrayReference, void * referenceobject) \
+{ \
+ XdmfArrayReferenceSetConstructedProperties((XDMFARRAYREFERENCE *)((void *)arrayReference), referenceobject); \
+} \
+ \
+void ClassName##SetConstructedType(CClassName * arrayReference, char * newType) \
+{ \
+ XdmfArrayReferenceSetConstructedType((XDMFARRAYREFERENCE *)((void *)arrayReference), newType); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFARRAYREFERENCE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfArrayType.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <sstream>
+#include <utility>
+#include <boost/assign.hpp>
+#include "string.h"
+#include "XdmfArrayType.hpp"
+#include "XdmfError.hpp"
+
+std::map<std::string, std::map<unsigned int ,shared_ptr<const XdmfArrayType>(*)()> >
+ XdmfArrayType::mArrayDefinitions;
+
+// Supported XdmfArrayTypes
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Uninitialized()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("None", 0, XdmfArrayType::Unsigned));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Int8()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("Char", 1, XdmfArrayType::Signed));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Int16()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("Short", 2, XdmfArrayType::Signed));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Int32()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("Int", 4, XdmfArrayType::Signed));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Int64()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("Int", 8, XdmfArrayType::Signed));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Float32()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("Float", 4, XdmfArrayType::Float));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::Float64()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("Float", 8, XdmfArrayType::Float));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::UInt8()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("UChar", 1, XdmfArrayType::Unsigned));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::UInt16()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("UShort", 2, XdmfArrayType::Unsigned));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::UInt32()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("UInt", 4, XdmfArrayType::Unsigned));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::UInt64()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("UInt", 8, XdmfArrayType::Unsigned));
+ return p;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::String()
+{
+ static shared_ptr<const XdmfArrayType> p(new XdmfArrayType("String", 0, XdmfArrayType::Unsigned));
+ return p;
+}
+
+void
+XdmfArrayType::InitTypes()
+{
+ mArrayDefinitions["NONE"][0] = Uninitialized;
+ mArrayDefinitions["CHAR"][1] = Int8;
+ mArrayDefinitions["SHORT"][2] = Int16;
+ mArrayDefinitions["INT"][4] = Int32;
+ mArrayDefinitions["INT"][8] = Int64;
+ mArrayDefinitions["FLOAT"][4] = Float32;
+ mArrayDefinitions["FLOAT"][8] = Float64;
+ mArrayDefinitions["UCHAR"][1] = UInt8;
+ mArrayDefinitions["USHORT"][2] = UInt16;
+ mArrayDefinitions["UINT"][4] = UInt32;
+ mArrayDefinitions["UINT"][8] = UInt64;
+ mArrayDefinitions["STRING"][0] = String;
+}
+
+XdmfArrayType::XdmfArrayType(const std::string & name,
+ const unsigned int precision,
+ const Format typeFormat) :
+ mName(name),
+ mPrecision(precision),
+ mTypeFormat(typeFormat)
+{
+ std::stringstream precisionString;
+ precisionString << precision;
+ mPrecisionString = precisionString.str();
+}
+
+XdmfArrayType::~XdmfArrayType()
+{
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::New(const std::map<std::string, std::string> & itemProperties)
+{
+ InitTypes();
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("DataType");
+ if(type == itemProperties.end()) {
+ type = itemProperties.find("NumberType");
+ }
+ if(type == itemProperties.end()) {
+ // to support old xdmf defaults, return Float32()
+ return Float32();
+ }
+ const std::string & typeVal = ConvertToUpper(type->second);
+ std::map<std::string, std::string>::const_iterator precision =
+ itemProperties.find("Precision");
+ const unsigned int precisionVal =
+ (precision == itemProperties.end()) ? 0 : atoi(precision->second.c_str());
+ std::map<std::string, std::map<unsigned int ,shared_ptr<const XdmfArrayType>(*)()> >::const_iterator returnType = mArrayDefinitions.find(typeVal);
+ if (returnType == mArrayDefinitions.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Type not one of accepted values: " + typeVal +
+ " in XdmfArrayType::New");
+ }
+ else {
+ std::map<unsigned int ,shared_ptr<const XdmfArrayType>(*)()>::const_iterator returnPrecision = returnType->second.find(precisionVal);
+
+ // If only one precision is available, assume that if not specified.
+ if (returnType->second.size() == 1 && precisionVal == 0)
+ {
+ return (*((returnType->second.begin())->second))();
+ }
+
+ if (returnPrecision == returnType->second.end()) {
+ // Default to 32bit types if not specified otherwise
+ returnPrecision = returnType->second.find(4);
+ }
+
+ if (returnPrecision == returnType->second.end()) {
+ std::string errorVal = "";
+ if (precision == itemProperties.end()) {
+ errorVal = "0";
+ }
+ else {
+ errorVal = precision->second;
+ }
+ XdmfError::message(XdmfError::FATAL,
+ "Type not one of accepted precision: " + errorVal +
+ " in XdmfArrayType::New");
+ }
+ else {
+ return (*(returnPrecision->second))();
+ }
+ }
+
+ XdmfError::message(XdmfError::FATAL,
+ "Type not one of accepted values: " + typeVal +
+ " in XdmfArrayType::New");
+
+ // unreachable
+ return shared_ptr<const XdmfArrayType>();
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfArrayType::comparePrecision(shared_ptr<const XdmfArrayType> type1,
+ shared_ptr<const XdmfArrayType> type2)
+{
+ std::string type1Name = type1->getName();
+ std::string type2Name = type2->getName();
+
+ if (type2Name.compare(type1Name) == 0) {
+ if (type1->getElementSize() >= type2->getElementSize()) {
+ return type1;
+ }
+ else {
+ return type2;
+ }
+ }
+
+ bool firstIsSigned = false;
+ if (type1Name.compare("UChar") != 0 &&
+ type1Name.compare("UShort") != 0 &&
+ type1Name.compare("UInt") != 0) {
+ firstIsSigned = true;
+ }
+
+ bool secondIsSigned = false;
+ if (type2Name.compare("UChar") != 0 &&
+ type2Name.compare("UShort") != 0 &&
+ type2Name.compare("UInt") != 0) {
+ secondIsSigned = true;
+ }
+
+ std::map<std::string, int> controlmap;
+ controlmap["Char"] = 1;
+ controlmap["UChar"] = 2;
+ controlmap["Short"] = 3;
+ controlmap["UShort"] = 4;
+ controlmap["Int"] = 5;
+ controlmap["UInt"] = 6;
+ controlmap["Float"] = 7;
+ controlmap["String"] = 8;
+
+ int control = controlmap[type1Name];
+
+
+ // In this switch the starting location is determined by
+ // the first type and then the algorithm cascades
+ // until it finds the second type
+ switch (control) {
+ case 1:
+ // Char
+ case 2:
+ // UChar
+ if (type2Name.compare("Char") == 0 ||
+ type2Name.compare("UChar") == 0) {
+ // This statement would be called in the case
+ // where there is a mixed type of Char and UChar
+ // The resulting type should be a Short
+ return Int16();
+ }
+ case 3:
+ // Short
+ if (type2Name.compare("Char") == 0 ||
+ type2Name.compare("UChar") == 0 ||
+ type2Name.compare("Short") == 0) {
+ // This will be called for any combination of
+ // Char/UChar and Short
+ // In all of these cases the result should be a Short
+ return Int16();
+ }
+ case 4:
+ // UShort
+ if (type2Name.compare("Char") == 0 ||
+ type2Name.compare("Short") == 0) {
+ // When mixing UShort with a signed type that has a lower precision
+ // the resulting type should be an int
+ return Int32();
+ }
+ else if (type2Name.compare("UChar") == 0 ||
+ type2Name.compare("UShort") == 0) {
+ // When mixing UShort with an unsigned type that has a lower precision
+ // a Ushort should be the resulting type
+ if (!firstIsSigned) {
+ return UInt16();
+ }
+ else {
+ return Int32();
+ }
+ }
+ case 5:
+ // Int
+ if (type2Name.compare("Int") != 0 &&
+ type2Name.compare("UInt") != 0 &&
+ type2Name.compare("Float") != 0 &&
+ type2Name.compare("String") != 0) {
+ // When mixing an Int with a type of lower precision
+ // the resulting type should match the Int's precision
+ if (type1->getElementSize() == 4) {
+ return Int32();
+ }
+ else {
+ return Int64();
+ }
+ }
+ if (type2Name.compare("Int") == 0) {
+ if (type2->getElementSize() == 4) {
+ return Int32();
+ }
+ else {
+ return Int64();
+ }
+ }
+ case 6:
+ // UInt
+ if (type2Name.compare("UInt") != 0 &&
+ type2Name.compare("Int") != 0 &&
+ type2Name.compare("Float") != 0 &&
+ type2Name.compare("String") != 0) {
+ // When mixing UInt with another non-floating-point type
+ // the result should be either long or unsigned int
+ // depending on the if the mixed type is signed or not
+ if (!secondIsSigned) {
+ if(type1->getElementSize() ==4) {
+ return UInt32();
+ }
+ else {
+ return UInt64();
+ }
+ }
+ else {
+ return Int64();
+ }
+ }
+ else if (type2Name.compare("UInt") == 0) {
+ if (firstIsSigned) {
+ return Int64();
+ }
+ else {
+ if (type2->getElementSize() == 4) {
+ return UInt32();
+ }
+ else {
+ return UInt64();
+ }
+ }
+ }
+ else if (type2Name.compare("Int") == 0) {
+ return Int64();
+ }
+ case 7:
+ // Float
+ if (type2Name.compare("String") != 0 &&
+ type2Name.compare("Float") != 0 &&
+ type2Name.compare("UInt") != 0) {
+ // String is the only type that has priority over a float
+ // This case occurs when type1 is a float
+ return type1;
+ }
+ else if (type2Name.compare("UInt") == 0) {
+ return Float64();
+ }
+ else if (type2Name.compare("Float") == 0) {
+ // Since there was a check earlier to see if the type names matched
+ // This is the case when type2 is a float
+ if (type1Name.compare("UInt") == 0) {
+ return Float64();
+ }
+ else {
+ return type2;
+ }
+ }
+ case 8:
+ // String
+ // String has priority over everything
+ return String();
+ default:
+ break;
+ }
+ // Double is the default value
+ // Should all of the above manage to fail to return a value
+ return Float64();
+}
+
+unsigned int
+XdmfArrayType::getElementSize() const
+{
+ return mPrecision;
+}
+
+std::string
+XdmfArrayType::getName() const
+{
+ return mName;
+}
+
+bool
+XdmfArrayType::getIsFloat() const
+{
+ if (mTypeFormat == XdmfArrayType::Float) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+bool
+XdmfArrayType::getIsSigned() const
+{
+ if (mTypeFormat == XdmfArrayType::Float ||
+ mTypeFormat == XdmfArrayType::Signed) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+void
+XdmfArrayType::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties.insert(std::make_pair("DataType", mName));
+ collectedProperties.insert(std::make_pair("Precision", mPrecisionString));
+}
+
+// C Wrappers
+
+shared_ptr<const XdmfArrayType>
+intToType(int type)
+{
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ return XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ return XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ return XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ return XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ return XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ return XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ return XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ return XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ return XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ return XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ return shared_ptr<const XdmfArrayType>();
+}
+
+int
+typeToInt(shared_ptr<const XdmfArrayType> type)
+{
+ std::string typeName = type->getName();
+ unsigned int typePrecision = type->getElementSize();
+ if (typeName == XdmfArrayType::UInt8()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT8;
+ }
+ else if (typeName == XdmfArrayType::UInt16()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT16;
+ }
+ else if (typeName == XdmfArrayType::UInt32()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT32;
+ }
+ else if (typeName == XdmfArrayType::UInt64()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT64;
+ }
+ else if (typeName == XdmfArrayType::Int8()->getName())
+ {
+ return XDMF_ARRAY_TYPE_INT8;
+ }
+ else if (typeName == XdmfArrayType::Int16()->getName())
+ {
+ return XDMF_ARRAY_TYPE_INT16;
+ }
+ else if (typeName == XdmfArrayType::Int32()->getName() || typeName == XdmfArrayType::Int64()->getName())
+ {
+ if (typePrecision == 4)
+ {
+ return XDMF_ARRAY_TYPE_INT32;
+ }
+ else if (typePrecision == 8)
+ {
+ return XDMF_ARRAY_TYPE_INT64;
+ }
+ else
+ {
+ }
+ }
+ else if (typeName == XdmfArrayType::Float32()->getName() || typeName == XdmfArrayType::Float64()->getName())
+ {
+ if (typePrecision == 4)
+ {
+ return XDMF_ARRAY_TYPE_FLOAT32;
+ }
+ else if (typePrecision == 8)
+ {
+ return XDMF_ARRAY_TYPE_FLOAT64;
+ }
+ else
+ {
+ }
+ }
+ else if (typeName == XdmfArrayType::String()->getName())
+ {
+ //This shouldn't be used from C bindings
+ XdmfError::message(XdmfError::FATAL,
+ "Error: String type not usable from C.");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ }
+ return -1;
+}
+
+int XdmfArrayTypeInt8()
+{
+ return XDMF_ARRAY_TYPE_INT8;
+}
+
+int XdmfArrayTypeInt16()
+{
+ return XDMF_ARRAY_TYPE_INT16;
+}
+
+int XdmfArrayTypeInt32()
+{
+ return XDMF_ARRAY_TYPE_INT32;
+}
+
+int XdmfArrayTypeInt64()
+{
+ return XDMF_ARRAY_TYPE_INT64;
+}
+
+int XdmfArrayTypeFloat32()
+{
+ return XDMF_ARRAY_TYPE_FLOAT32;
+}
+
+int XdmfArrayTypeFloat64()
+{
+ return XDMF_ARRAY_TYPE_FLOAT64;
+}
+
+int XdmfArrayTypeUInt8()
+{
+ return XDMF_ARRAY_TYPE_UINT8;
+}
+
+int XdmfArrayTypeUInt16()
+{
+ return XDMF_ARRAY_TYPE_UINT16;
+}
+
+int XdmfArrayTypeUInt32()
+{
+ return XDMF_ARRAY_TYPE_UINT32;
+}
+
+int XdmfArrayTypeUInt64()
+{
+ return XDMF_ARRAY_TYPE_UINT64;
+}
+
+int XdmfArrayTypeComparePrecision(int type1, int type2, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<const XdmfArrayType> tempType1 = intToType(type1);
+ shared_ptr<const XdmfArrayType> tempType2 = intToType(type2);
+ shared_ptr<const XdmfArrayType> returnType = XdmfArrayType::comparePrecision(tempType1, tempType2);
+ return typeToInt(returnType);
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+int XdmfArrayTypeGetElementSize(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return intToType(type)->getElementSize();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+int XdmfArrayTypeGetIsFloat(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return intToType(type)->getIsFloat();
+ XDMF_ERROR_WRAP_END(status)
+ return false;
+}
+
+int XdmfArrayTypeGetIsSigned(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return intToType(type)->getIsSigned();
+ XDMF_ERROR_WRAP_END(status)
+ return false;
+}
+
+char * XdmfArrayTypeGetName(int type, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ char * returnPointer = strdup(intToType(type)->getName().c_str());
+ return returnPointer;
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfArrayType.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFARRAYTYPE_HPP_
+#define XDMFARRAYTYPE_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include "XdmfItemProperty.hpp"
+#include <vector>
+
+/**
+ * @brief Property describing what types of values an XdmfArray
+ * contains.
+ *
+ * XdmfArrayType specifies the types of values stored in an XdmfArray.
+ * A specific XdmfArrayType can be created by calling one of the
+ * static methods in the class, i.e. XdmfArrayType::Int32().
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArrayType.cpp
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArrayType.py
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * Xdmf supports the following attribute types:
+ * Uninitialized
+ * Int8
+ * Int16
+ * Int32
+ * Int64
+ * Float32
+ * Float64
+ * UInt8
+ * UInt16
+ * UInt32
+ * UInt64
+ * String
+ */
+class XDMFCORE_EXPORT XdmfArrayType : public XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfArrayType();
+
+ friend class XdmfArray;
+ friend class XdmfCoreItemFactory;
+
+ enum Format {
+ Unsigned,
+ Signed,
+ Float
+ };
+
+ // Supported XdmfArrayTypes
+ static shared_ptr<const XdmfArrayType> Uninitialized();
+ static shared_ptr<const XdmfArrayType> Int8();
+ static shared_ptr<const XdmfArrayType> Int16();
+ static shared_ptr<const XdmfArrayType> Int32();
+ static shared_ptr<const XdmfArrayType> Int64();
+ static shared_ptr<const XdmfArrayType> Float32();
+ static shared_ptr<const XdmfArrayType> Float64();
+ static shared_ptr<const XdmfArrayType> UInt8();
+ static shared_ptr<const XdmfArrayType> UInt16();
+ static shared_ptr<const XdmfArrayType> UInt32();
+ static shared_ptr<const XdmfArrayType> UInt64();
+ static shared_ptr<const XdmfArrayType> String();
+
+ /**
+ * Compares the two types given and returns a type that is compatible with both.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @skipline //#comparePrecision
+ * @until //#comparePrecision
+ *
+ * Python
+ *
+ * @skipline #//comparePrecision
+ * @until #//comparePrecision
+ *
+ * @param type1 The first type to be compared
+ * @param type2 The second type to be compared
+ * @return The type that is compatible with both provided types
+ */
+ static shared_ptr<const XdmfArrayType> comparePrecision(shared_ptr<const XdmfArrayType> type1, shared_ptr<const XdmfArrayType> type2);
+
+ /**
+ * Get the data size, in bytes, of the value associated with this
+ * array type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArrayType.cpp
+ * @skipline //#getElementSize
+ * @until //#getElementSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArrayType.py
+ * @skipline #//getElementSize
+ * @until #//getElementSize
+ *
+ * @return The data size, in bytes.
+ */
+ unsigned int getElementSize() const;
+
+ /**
+ * Gets whether the data type is floating point or not.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArrayType.cpp
+ * @skipline //#getIsFloat
+ * @until //#getIsFloat
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArrayType.py
+ * @skipline #//getIsFloat
+ * @until #//getIsFloat
+ *
+ * @return Whether the data type is signed.
+ */
+ bool getIsFloat() const;
+
+ /**
+ * Gets whether the data type is signed or not.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArrayType.cpp
+ * @skipline //#getIsSigned
+ * @until //#getIsSigned
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArrayType.py
+ * @skipline #//getIsSigned
+ * @until #//getIsSigned
+ *
+ * @return Whether the data type is signed.
+ */
+ bool getIsSigned() const;
+
+ /**
+ * Get the name of the data type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfArrayType.cpp
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleArrayType.py
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return The name of the data type.
+ */
+ std::string getName() const;
+
+ void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+protected:
+
+ /**
+ * Protected constructor for XdmfArrayType. The constructor is
+ * protected because all array types supported by Xdmf should be
+ * accessed through more specific static methods that construct
+ * XdmfArrayTypes - i.e. XdmfArrayType::Float64().
+ *
+ * @param name the name of the XdmfArrayType to construct.
+ * @param precision the precision, in bytes, of the XdmfArrayType to
+ * construct.
+ * @param typeFormat The format description of the XdmfArrayType.
+ */
+ XdmfArrayType(const std::string & name,
+ const unsigned int precision,
+ const Format typeFormat);
+
+ static std::map<std::string, std::map<unsigned int ,shared_ptr<const XdmfArrayType>(*)()> > mArrayDefinitions;
+
+ static void InitTypes();
+
+private:
+
+ XdmfArrayType(const XdmfArrayType &); // Not implemented.
+ void operator=(const XdmfArrayType &); // Not implemented.
+
+ static shared_ptr<const XdmfArrayType>
+ New(const std::map<std::string, std::string> & itemProperties);
+
+ const std::string mName;
+ const unsigned int mPrecision;
+ std::string mPrecisionString;
+ Format mTypeFormat;
+ const char * mTypeId;
+
+ // Allows for up to 16 byte sizes for unsigned, signed, and floating point types
+ // The vector is actually larger than that to allow for the string and uninitialized types
+ static std::vector<shared_ptr<const XdmfArrayType> > mTypes;
+ // Due to uninitialized taking position 0 the size of the array is actually one over the max size
+ static unsigned int mCurrentMaxSize;
+ // Map of typeid to index in mTypes
+ static std::map<std::string, shared_ptr<const XdmfArrayType> > mTypeIdMap;
+};
+
+#endif
+
+#define XDMF_ARRAY_TYPE_INT8 0
+#define XDMF_ARRAY_TYPE_INT16 1
+#define XDMF_ARRAY_TYPE_INT32 2
+#define XDMF_ARRAY_TYPE_INT64 3
+#define XDMF_ARRAY_TYPE_UINT8 4
+#define XDMF_ARRAY_TYPE_UINT16 5
+#define XDMF_ARRAY_TYPE_UINT32 6
+#define XDMF_ARRAY_TYPE_FLOAT32 7
+#define XDMF_ARRAY_TYPE_FLOAT64 8
+#define XDMF_ARRAY_TYPE_UINT64 9
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// These simply return the values defined above
+XDMFCORE_EXPORT int XdmfArrayTypeInt8();
+XDMFCORE_EXPORT int XdmfArrayTypeInt16();
+XDMFCORE_EXPORT int XdmfArrayTypeInt32();
+XDMFCORE_EXPORT int XdmfArrayTypeInt64();
+XDMFCORE_EXPORT int XdmfArrayTypeFloat32();
+XDMFCORE_EXPORT int XdmfArrayTypeFloat64();
+XDMFCORE_EXPORT int XdmfArrayTypeUInt8();
+XDMFCORE_EXPORT int XdmfArrayTypeUInt16();
+XDMFCORE_EXPORT int XdmfArrayTypeUInt32();
+XDMFCORE_EXPORT int XdmfArrayTypeUInt64();
+
+XDMFCORE_EXPORT int XdmfArrayTypeComparePrecision(int type1, int type2, int * status);
+
+XDMFCORE_EXPORT int XdmfArrayTypeGetElementSize(int type, int * status);
+
+XDMFCORE_EXPORT int XdmfArrayTypeGetIsFloat(int type, int * status);
+
+XDMFCORE_EXPORT int XdmfArrayTypeGetIsSigned(int type, int * status);
+
+XDMFCORE_EXPORT char * XdmfArrayTypeGetName(int type, int * status);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFARRAYTYPE_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* Xdmf */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfBinaryController.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <fstream>
+#include <sstream>
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfBinaryController.hpp"
+#include "XdmfError.hpp"
+
+namespace {
+
+ template<size_t T>
+ struct ByteSwaper {
+ static inline void swap(void * p){}
+ static inline void swap(void * p,
+ unsigned int length)
+ {
+ char * data = static_cast<char *>(p);
+ for(unsigned int i=0; i<length; ++i, data+=T){
+ ByteSwaper<T>::swap(data);
+ }
+ }
+ };
+
+ template<>
+ void ByteSwaper<2>::swap(void * p){
+ char one_byte;
+ char* data = static_cast<char*>(p);
+ one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
+ }
+
+ template<>
+ void ByteSwaper<4>::swap(void * p){
+ char one_byte;
+ char* data = static_cast<char*>(p);
+ one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
+ one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
+
+ }
+
+ template<>
+ void ByteSwaper<8>::swap(void * p){
+ char one_byte;
+ char* data = static_cast<char*>(p);
+ one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
+ one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
+ one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
+ one_byte = data[3]; data[3] = data[4]; data[4] = one_byte;
+ }
+
+}
+
+shared_ptr<XdmfBinaryController>
+XdmfBinaryController::New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const Endian & endian,
+ const unsigned int seek,
+ const std::vector<unsigned int> & dimensions)
+{
+ shared_ptr<XdmfBinaryController> p(new XdmfBinaryController(filePath,
+ type,
+ endian,
+ seek,
+ std::vector<unsigned int>(dimensions.size(), 0),
+ std::vector<unsigned int>(dimensions.size(), 1),
+ dimensions,
+ dimensions));
+ return p;
+}
+
+shared_ptr<XdmfBinaryController>
+XdmfBinaryController::New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const Endian & endian,
+ const unsigned int seek,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces)
+{
+ shared_ptr<XdmfBinaryController> p(new XdmfBinaryController(filePath,
+ type,
+ endian,
+ seek,
+ starts,
+ strides,
+ dimensions,
+ dataspaces));
+ return p;
+}
+
+XdmfBinaryController::XdmfBinaryController(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const Endian & endian,
+ const unsigned int seek,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces) :
+ XdmfHeavyDataController(filePath,
+ type,
+ starts,
+ strides,
+ dimensions,
+ dataspaces),
+ mEndian(endian),
+ mSeek(seek)
+{
+}
+
+XdmfBinaryController::XdmfBinaryController(const XdmfBinaryController & refController):
+ XdmfHeavyDataController(refController),
+ mEndian(refController.mEndian),
+ mSeek(refController.mSeek)
+{
+}
+
+XdmfBinaryController::~XdmfBinaryController()
+{
+}
+
+std::string
+XdmfBinaryController::getDataspaceDescription() const
+{
+ std::stringstream descstream;
+ descstream << mSeek << ":" << XdmfHeavyDataController::getDataspaceDescription();
+ return descstream.str();
+}
+
+XdmfBinaryController::Endian
+XdmfBinaryController::getEndian() const
+{
+ return mEndian;
+}
+
+std::string
+XdmfBinaryController::getName() const
+{
+ return "Binary";
+}
+
+void
+XdmfBinaryController::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties["Format"] = this->getName();
+
+ if(mEndian == BIG) {
+ collectedProperties["Endian"] = "Big";
+ }
+ else if(mEndian == LITTLE) {
+ collectedProperties["Endian"] = "Little";
+ }
+}
+
+unsigned int
+XdmfBinaryController::getSeek() const
+{
+ return mSeek;
+}
+
+void
+XdmfBinaryController::read(XdmfArray * const array)
+{
+ array->initialize(mType, mDimensions);
+
+ shared_ptr<XdmfArray> dataspaceArray = XdmfArray::New();
+
+ dataspaceArray->initialize(mType, mDataspaceDimensions);
+
+ std::ifstream fileStream(mFilePath.c_str(),
+ std::ifstream::binary);
+
+ if(!fileStream.good()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error reading " + mFilePath +
+ " in XdmfBinaryController::read");
+ }
+
+ fileStream.seekg(mSeek);
+
+ if(!fileStream.good()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error seeking " + mFilePath +
+ " in XdmfBinaryController::read");
+ }
+
+ fileStream.read(static_cast<char *>(dataspaceArray->getValuesInternal()),
+ dataspaceArray->getSize() * mType->getElementSize());
+
+#if defined(XDMF_BIG_ENDIAN)
+ const bool needByteSwap = mEndian == LITTLE;
+#else
+ const bool needByteSwap = mEndian == BIG;
+#endif // XDMF_BIG_ENDIAN
+
+ if(needByteSwap) {
+ switch(mType->getElementSize()){
+ case 1:
+ break;
+ case 2:
+ ByteSwaper<2>::swap(dataspaceArray->getValuesInternal(),
+ dataspaceArray->getSize());
+ break;
+ case 4:
+ ByteSwaper<4>::swap(dataspaceArray->getValuesInternal(),
+ dataspaceArray->getSize());
+ break;
+ case 8:
+ ByteSwaper<8>::swap(dataspaceArray->getValuesInternal(),
+ dataspaceArray->getSize());
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Cannot perform endianness swap for datatype");
+ break;
+ }
+ }
+ array->insert(std::vector<unsigned int>(mDimensions.size(), 0),
+ dataspaceArray,
+ mStart,
+ mDataspaceDimensions,
+ mDimensions,
+ std::vector<unsigned int>(mDimensions.size(), 1),
+ mStride);
+}
+
+// C Wrappers
+
+XDMFBINARYCONTROLLER *
+XdmfBinaryControllerNew(char * filePath,
+ int type,
+ int endian,
+ unsigned int seek,
+ unsigned int * dimensions,
+ unsigned int numDims,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ XdmfBinaryController::Endian buildEndian = XdmfBinaryController::NATIVE;
+ printf("switch endian = %u\n", endian);
+ switch (endian) {
+ case XDMF_BINARY_CONTROLLER_ENDIAN_BIG:
+ buildEndian = XdmfBinaryController::BIG;
+ break;
+ case XDMF_BINARY_CONTROLLER_ENDIAN_LITTLE:
+ buildEndian = XdmfBinaryController::LITTLE;
+ break;
+ case XDMF_BINARY_CONTROLLER_ENDIAN_NATIVE:
+ buildEndian = XdmfBinaryController::NATIVE;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Endian.");
+ break;
+ }
+ shared_ptr<XdmfBinaryController> generatedController = XdmfBinaryController::New(std::string(filePath), buildType, buildEndian, seek, dimVector);
+ return (XDMFBINARYCONTROLLER *)((void *)(new XdmfBinaryController(*generatedController.get())));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFBINARYCONTROLLER *
+XdmfBinaryControllerNewHyperslab(char * filePath,
+ int type,
+ int endian,
+ unsigned int seek,
+ unsigned int * start,
+ unsigned int * stride,
+ unsigned int * dimensions,
+ unsigned int * dataspaceDimensions,
+ unsigned int numDims,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ XdmfBinaryController::Endian buildEndian = XdmfBinaryController::NATIVE;
+ switch (endian) {
+ case XDMF_BINARY_CONTROLLER_ENDIAN_BIG:
+ buildEndian = XdmfBinaryController::BIG;
+ break;
+ case XDMF_BINARY_CONTROLLER_ENDIAN_LITTLE:
+ buildEndian = XdmfBinaryController::LITTLE;
+ break;
+ case XDMF_BINARY_CONTROLLER_ENDIAN_NATIVE:
+ buildEndian = XdmfBinaryController::NATIVE;
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Endian.");
+ break;
+ }
+ shared_ptr<XdmfBinaryController> generatedController = XdmfBinaryController::New(std::string(filePath), buildType, buildEndian, seek, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFBINARYCONTROLLER *)((void *)(new XdmfBinaryController(*generatedController.get())));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+int
+XdmfBinaryControllerGetEndian(XDMFBINARYCONTROLLER * controller)
+{
+ return ((XdmfBinaryController *)(controller))->getEndian();
+}
+
+unsigned int
+XdmfBinaryControllerGetSeek(XDMFBINARYCONTROLLER * controller)
+{
+ return ((XdmfBinaryController *)(controller))->getSeek();
+}
+
+// C Wrappers for parent classes are generated by macros
+XDMF_HEAVYCONTROLLER_C_CHILD_WRAPPER(XdmfBinaryController, XDMFBINARYCONTROLLER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfBinaryController.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFBinaryCONTROLLER_HPP_
+#define XDMFBinaryCONTROLLER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataController.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Couples an XdmfArray with Binary data stored on disk.
+ *
+ * Serves as an interface between data stored in XdmfArrays and data
+ * stored in binary files on disk. When an Xdmf file is read from or
+ * written to disk an XdmfBinaryController is attached to
+ * XdmfArrays. This allows data to be released from memory but still
+ * be accessible or have its location written to light data.
+ */
+class XDMFCORE_EXPORT XdmfBinaryController : public XdmfHeavyDataController {
+
+public:
+
+ typedef enum Endian {
+ BIG,
+ LITTLE,
+ NATIVE
+ } Endian;
+
+ virtual ~XdmfBinaryController();
+
+ /**
+ * Create a new controller for an binary data set on disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfBinaryController.cpp
+ * @skipline //#initializationsimplified
+ * @until //#initializationsimplified
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleBinaryController.py
+ * @skipline #//initializationsimplified
+ * @until #//initializationsimplified
+ *
+ * @param filePath Location of the binary file.
+ * @param type Data type of the dataset to read.
+ * @param endian Endianness of the data.
+ * @param seek Distance in bytes to begin reading in file.
+ * @param dimensions Number of elements to select in each from the total
+ *
+ * @return New Binary Controller.
+ */
+ static shared_ptr<XdmfBinaryController>
+ New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const Endian & endian,
+ const unsigned int seek,
+ const std::vector<unsigned int> & dimensions);
+
+ /**
+ * Create a new controller for an binary data set on disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfBinaryController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleBinaryController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param filePath Location of the binary file.
+ * @param type Data type of the dataset to read.
+ * @param endian Endianness of the data.
+ * @param seek Distance in bytes to begin reading in file.
+ * @param starts Starting index for each dimension
+ * @param strides Distance between read values across the dataspace
+ * @param dimensions Number of elements to select in each from the total
+ * @param dataspaces Total number of elements to select in each
+ *
+ * @return New Binary Controller.
+ */
+ static shared_ptr<XdmfBinaryController>
+ New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const Endian & endian,
+ const unsigned int seek,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces);
+
+ virtual std::string getDataspaceDescription() const;
+
+ /**
+ * Gets the endianness of the dataset that the controller points to.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfBinaryController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getEndian
+ * @until //#getEndian
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleBinaryController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getEndian
+ * @until #//getEndian
+ *
+ * @return The endianness of the dataset.
+ */
+ virtual Endian getEndian() const;
+
+ virtual std::string getName() const;
+
+ virtual void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+ /**
+ * Gets the offset in bytes of the dataset that the controller points to in the file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfBinaryController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getSeek
+ * @until //#getSeek
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleBinaryController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getSeek
+ * @until #//getSeek
+ *
+ * @return The offset in bytes.
+ */
+ virtual unsigned int getSeek() const;
+
+ virtual void read(XdmfArray * const array);
+
+ XdmfBinaryController(const XdmfBinaryController &);
+
+protected:
+
+ XdmfBinaryController(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const Endian & endian,
+ const unsigned int seek,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces);
+
+private:
+
+ void operator=(const XdmfBinaryController &); // Not implemented.
+
+ const Endian mEndian;
+ const unsigned int mSeek;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define XDMF_BINARY_CONTROLLER_ENDIAN_BIG 50
+#define XDMF_BINARY_CONTROLLER_ENDIAN_LITTLE 51
+#define XDMF_BINARY_CONTROLLER_ENDIAN_NATIVE 52
+
+struct XDMFBINARYCONTROLLER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFBINARYCONTROLLER XDMFBINARYCONTROLLER;
+
+XDMFCORE_EXPORT XDMFBINARYCONTROLLER * XdmfBinaryControllerNew(char * filePath,
+ int type,
+ int endian,
+ unsigned int seek,
+ unsigned int * dimensions,
+ unsigned int numDims,
+ int * status);
+
+XDMFCORE_EXPORT XDMFBINARYCONTROLLER * XdmfBinaryControllerNewHyperslab(char * filePath,
+ int type,
+ int endian,
+ unsigned int seek,
+ unsigned int * starts,
+ unsigned int * strides,
+ unsigned int * dimensions,
+ unsigned int * dataspaces,
+ unsigned int numDims,
+ int * status);
+
+XDMFCORE_EXPORT int XdmfBinaryControllerGetEndian(XDMFBINARYCONTROLLER * controller);
+
+XDMFCORE_EXPORT unsigned int XdmfBinaryControllerGetSeek(XDMFBINARYCONTROLLER * controller);
+
+XDMF_HEAVYCONTROLLER_C_CHILD_DECLARE(XdmfBinaryController, XDMFBINARYCONTROLLER, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFBinaryCONTROLLER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfConfig.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFCONFIG_HPP_
+#define XDMFCONFIG_HPP_
+
+#cmakedefine HAVE_BOOST_SHARED_DYNAMIC_CAST
+#cmakedefine HAVE_CXX11_ENABLE_IF
+#cmakedefine XDMF_BIG_ENDIAN
+
+#endif /* XDMFSHAREDPTR_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCore.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef _XDMF_HPP
+#ifndef _XDMFCORE_HPP
+#define _XDMFCORE_HPP
+
+#include "XdmfCoreConfig.hpp"
+
+/* Keep all our Win32 Conversions here */
+#ifdef _WIN32
+# ifdef XDMFSTATIC
+# define XDMFCORE_EXPORT
+# define XDMFCORE_TEMPLATE
+# else
+ /* Used to export/import from the dlls */
+# ifdef XdmfCore_EXPORTS
+# define XDMFCORE_EXPORT __declspec(dllexport)
+# define XDMFCORE_TEMPLATE
+# else /* Xdmf_EXPORTS */
+# define XDMFCORE_EXPORT __declspec(dllimport)
+# define XDMFCORE_TEMPLATE extern
+# endif /* Xdmf_EXPORTS */
+# endif
+
+/* Used in XdmfSystemUtils */
+#define PATH_MAX _MAX_PATH
+#define realpath(x,y) _fullpath((char *) y,x, _MAX_PATH)
+
+/* Compiler Warnings */
+#ifndef XDMF_DEBUG
+#pragma warning( disable : 4231 ) /* nonstandard extension used : 'extern' before template explicit instantiation */
+#pragma warning( disable : 4251 ) /* needs to have dll-interface to be used by clients (Most of these guys are in private */
+#pragma warning( disable : 4275 ) /* non dll-interface class 'std::_Container_base_aux' used as base for dll-interface class */
+#pragma warning( disable : 4373 ) /* virtual function overrides, parameters only differed by const/volatile qualifiers */
+#pragma warning( disable : 4101 ) /* 'exception' : unreferenced local variable */
+#pragma warning( disable : 4355 ) /* 'this' : used in base member initializer list */
+#pragma warning( disable : 4748 ) /* /GS can not protect parameters and local variables from local buffer overrun (turned off op)*/
+#endif /* XDMF_DEBUG */
+
+/* Compiler Optimizations will result in an 'internal compiler error', so turn them off */
+#pragma optimize("g", off)
+#pragma warning( disable : 4297 ) /* __declspec(nothrow), throw(), noexcept(true), or noexcept was specified in the function */
+#pragma warning( disable : 4800 ) /* 'int': forcing value to bool 'true' or 'false' (performance warning) */
+#pragma warning( disable : 4521 ) /* multiple copy constructors */
+#else /* _WIN32 */
+
+/* We don't need to export/import since there are no dlls */
+#define XDMFCORE_EXPORT
+#define XDMFCORE_TEMPLATE
+
+#endif /* _WIN32 */
+
+#endif /* _XDMFCORE_HPP */
+#endif /*_XDMF_HPP */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCoreConfig.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFCORECONFIG_HPP_
+#define XDMFCORECONFIG_HPP_
+
+#cmakedefine HAVE_BOOST_SHARED_DYNAMIC_CAST
+#cmakedefine XDMF_BIG_ENDIAN
+
+#cmakedefine BUILD_SHARED
+#ifndef BUILD_SHARED
+# define XDMFSTATIC
+#endif
+
+#cmakedefine XDMF_NO_REALPATH
+
+#endif /* XDMFCORECONFIG_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCoreItemFactory.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfArray.hpp"
+#include "XdmfBinaryController.hpp"
+#include "XdmfCoreItemFactory.hpp"
+#include "XdmfError.hpp"
+#include "XdmfFunction.hpp"
+#include "XdmfHDF5Controller.hpp"
+#include "XdmfHDF5Writer.hpp"
+#include "XdmfSubset.hpp"
+#include "XdmfTIFFController.hpp"
+#include "XdmfInformation.hpp"
+#include "XdmfSparseMatrix.hpp"
+#include <boost/tokenizer.hpp>
+#include <string.h>
+
+std::string
+XdmfCoreItemFactory::getFullHeavyDataPath(const std::string & filePath,
+ const std::map<std::string, std::string> & itemProperties) const
+{
+ // FIXME: for other OS (e.g. windows)
+ if(filePath.size() > 0 && filePath[0] != '/') {
+ // Dealing with a relative path for heavyData location
+ std::map<std::string, std::string>::const_iterator xmlDir =
+ itemProperties.find("XMLDir");
+ if(xmlDir == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'XMLDir' not found in itemProperties when "
+ "building full heavy data path");
+ }
+ std::stringstream newHeavyDataPath;
+ newHeavyDataPath << xmlDir->second << filePath;
+ return newHeavyDataPath.str();
+ }
+ return filePath;
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfCoreItemFactory::getArrayType(const std::map<std::string, std::string> & itemProperties) const
+{
+ return XdmfArrayType::New(itemProperties);
+}
+
+XdmfCoreItemFactory::XdmfCoreItemFactory()
+{
+}
+
+XdmfCoreItemFactory::~XdmfCoreItemFactory()
+{
+}
+
+shared_ptr<XdmfItem>
+XdmfCoreItemFactory::createItem(const std::string & itemTag,
+ const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems) const
+{
+ if(itemTag.compare(XdmfArray::ItemTag) == 0) {
+ return XdmfArray::New();
+ }
+ else if(itemTag.compare("DataStructure") == 0) {
+ // to support old xdmf DataStructure tag
+ return XdmfArray::New();
+ }
+ else if (itemTag.compare(XdmfFunction::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("ConstructedType");
+ std::string arraySubType;
+ if(type == itemProperties.end()) {
+ // If no type is specified an array is generated
+ arraySubType = XdmfArray::ItemTag;
+ }
+ else {
+ arraySubType = type->second;
+ }
+ std::map<std::string, std::string>::const_iterator expression =
+ itemProperties.find("Expression");
+ std::string expressionToParse;
+ if(expression == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Function found no expression");
+ }
+ else {
+ expressionToParse = expression->second;
+ }
+
+ std::map<std::string, std::string>::const_iterator variableNames =
+ itemProperties.find("VariableNames");
+ std::vector<std::string> nameVector;
+
+ std::string variableList = variableNames->second;
+
+ size_t barSplit = 0;
+ std::string subcontent;
+ while (barSplit != std::string::npos) {
+ barSplit = 0;
+ barSplit = variableList.find_first_of("|", barSplit);
+ if (barSplit == std::string::npos) {
+ subcontent = variableList;
+ }
+ else {
+ subcontent = variableList.substr(0, barSplit);
+ variableList = variableList.substr(barSplit+1);
+ barSplit++;
+ }
+ nameVector.push_back(subcontent);
+ }
+
+
+ std::map<std::string, shared_ptr<XdmfArray> > variableCollection;
+ for (unsigned int i = 0; i < childItems.size() && i < nameVector.size(); ++i) {
+ if (nameVector[i].compare("") != 0) {
+ if (shared_ptr<XdmfArray> array =
+ shared_dynamic_cast<XdmfArray>(childItems[i])) {
+
+ variableCollection[nameVector[i]] = array;
+ array->read();
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Function passed non-Array item");
+ }
+ }
+ }
+
+ shared_ptr<XdmfArray> parsedArray = shared_ptr<XdmfArray>();
+ parsedArray = XdmfFunction::evaluateExpression(expressionToParse,
+ variableCollection);
+ if (arraySubType != XdmfArray::ItemTag) {
+ // The properties and children aren't really needed
+ // to generate the object, but the factory still requires them.
+ std::vector<shared_ptr<XdmfItem> > newArrayChildren;
+ shared_ptr<XdmfArray> returnArray = shared_ptr<XdmfArray>();
+
+ // This should generate an item that corresponds to the tag provided
+ // the casting ensures that it is a subtype of array
+ // Using a factory to be able to build things outside of core
+ returnArray = shared_dynamic_cast<XdmfArray>(createItem(
+ arraySubType,
+ itemProperties,
+ newArrayChildren));
+
+ returnArray->insert(0, parsedArray, 0, parsedArray->getSize());
+ returnArray->setReference(XdmfFunction::New(expressionToParse,
+ variableCollection));
+ returnArray->setReadMode(XdmfArray::Reference);
+ return returnArray;
+ }
+ else {
+ parsedArray->setReference(XdmfFunction::New(expressionToParse,
+ variableCollection));
+ parsedArray->setReadMode(XdmfArray::Reference);
+ return parsedArray;
+ }
+ }
+ else if(itemTag.compare(XdmfSubset::ItemTag) == 0) {
+ std::map<std::string, std::string>::const_iterator type =
+ itemProperties.find("ConstructedType");
+ std::string arraySubType;
+ if(type == itemProperties.end()) {
+ // If no type is specified an array is generated
+ arraySubType = XdmfArray::ItemTag;
+ }
+ else {
+ arraySubType = type->second;
+ }
+
+ std::vector<shared_ptr<XdmfItem> > newArrayChildren;
+ shared_ptr<XdmfArray> returnArray = shared_ptr<XdmfArray>();
+
+ returnArray = shared_dynamic_cast<XdmfArray>(createItem(
+ arraySubType,
+ itemProperties,
+ newArrayChildren));
+
+ std::vector<unsigned int> startVector;
+ std::vector<unsigned int> strideVector;
+ std::vector<unsigned int> dimensionVector;
+ shared_ptr<XdmfArray> referenceArray;
+
+ std::map<std::string, std::string>::const_iterator starts =
+ itemProperties.find("SubsetStarts");
+
+ boost::tokenizer<> tokens(starts->second);
+ for(boost::tokenizer<>::const_iterator iter = tokens.begin();
+ iter != tokens.end();
+ ++iter) {
+ startVector.push_back(atoi((*iter).c_str()));
+ }
+
+ std::map<std::string, std::string>::const_iterator strides =
+ itemProperties.find("SubsetStrides");
+
+ boost::tokenizer<> stridetokens(strides->second);
+ for(boost::tokenizer<>::const_iterator iter = stridetokens.begin();
+ iter != stridetokens.end();
+ ++iter) {
+ strideVector.push_back(atoi((*iter).c_str()));
+ }
+
+ std::map<std::string, std::string>::const_iterator dimensions =
+ itemProperties.find("SubsetDimensions");
+
+ boost::tokenizer<> dimtokens(dimensions->second);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ dimensionVector.push_back(atoi((*iter).c_str()));
+ }
+
+ bool foundspacer = false;
+
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ if (foundspacer) {
+ referenceArray = shared_dynamic_cast<XdmfArray>(array);
+ break;
+ }
+ else {
+ foundspacer = true;
+ }
+ }
+ }
+
+ shared_ptr<XdmfSubset> newSubset = XdmfSubset::New(referenceArray,
+ startVector,
+ strideVector,
+ dimensionVector);
+
+ returnArray->setReference(newSubset);
+ returnArray->setReadMode(XdmfArray::Reference);
+
+ return returnArray;
+
+ }
+ return shared_ptr<XdmfItem>();
+}
+
+std::vector<shared_ptr<XdmfHeavyDataController> >
+XdmfCoreItemFactory::generateHeavyDataControllers(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<unsigned int> & passedDimensions,
+ shared_ptr<const XdmfArrayType> passedArrayType,
+ const std::string & passedFormat) const
+{
+ std::vector<shared_ptr<XdmfHeavyDataController> > returnControllers;
+
+ std::string formatVal;
+
+ if (passedFormat.size() > 0)
+ {
+ formatVal = passedFormat;
+ }
+ else
+ {
+ // create a version that passes these in directly
+ std::map<std::string, std::string>::const_iterator format =
+ itemProperties.find("Format");
+ if(format == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Format' not found in generateHeavyControllers in "
+ "XdmfCoreItemFactory");
+ }
+ formatVal = format->second;
+ }
+
+
+ std::map<std::string, std::string>::const_iterator content =
+ itemProperties.find("Content");
+ if(content == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Content' not found in generateHeavyControllers in "
+ "XdmfCoreItemFactory");
+ }
+
+ unsigned int contentIndex;
+
+ const std::string & contentVal = content->second;
+
+ std::vector<std::string> contentVals;
+
+ // Split the content based on "|" characters
+ size_t barSplit = 0;
+ std::string splitString(contentVal);
+ std::string subcontent;
+ while (barSplit != std::string::npos) {
+ barSplit = 0;
+ barSplit = splitString.find_first_of("|", barSplit);
+ if (barSplit == std::string::npos) {
+ subcontent = splitString;
+ }
+ else {
+ subcontent = splitString.substr(0, barSplit);
+ splitString = splitString.substr(barSplit+1);
+ barSplit++;
+ }
+ contentVals.push_back(subcontent);
+ }
+
+ std::vector<unsigned int> dimVector;
+
+ if (passedDimensions.size() > 0)
+ {
+ dimVector = passedDimensions;
+ }
+ else
+ {
+ std::map<std::string, std::string>::const_iterator dimensions =
+ itemProperties.find("Dimensions");
+ if(dimensions == itemProperties.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "'Dimensions' not found in generateHeavyControllers in "
+ "XdmfCoreItemFactory");
+ }
+
+ boost::tokenizer<> tokens(dimensions->second);
+ for(boost::tokenizer<>::const_iterator iter = tokens.begin();
+ iter != tokens.end();
+ ++iter) {
+ dimVector.push_back(atoi((*iter).c_str()));
+ }
+ }
+
+ shared_ptr<const XdmfArrayType> arrayType;
+ if (passedArrayType)
+ {
+ arrayType = passedArrayType;
+ }
+ else
+ {
+ arrayType = XdmfArrayType::New(itemProperties);
+ }
+
+ if (contentVals.size() == 0) {
+ return returnControllers;
+ }
+
+ if(formatVal.compare("Binary") == 0) {
+ contentIndex = 0;
+ int contentStep = 2;
+ while (contentIndex < contentVals.size()) {
+ XdmfBinaryController::Endian endian = XdmfBinaryController::NATIVE;
+ std::map<std::string, std::string>::const_iterator endianIter =
+ itemProperties.find("Endian");
+ if(endianIter != itemProperties.end()) {
+ if(endianIter->second.compare("Big") == 0) {
+ endian = XdmfBinaryController::BIG;
+ }
+ else if(endianIter->second.compare("Little") == 0) {
+ endian = XdmfBinaryController::LITTLE;
+ }
+ else if(endianIter->second.compare("Native") == 0) {
+ endian = XdmfBinaryController::NATIVE;
+ }
+ else {
+ XdmfError(XdmfError::FATAL,
+ "Invalid endianness type: " + endianIter->second);
+ }
+ }
+
+ unsigned int seek = 0;
+ std::map<std::string, std::string>::const_iterator seekIter =
+ itemProperties.find("Seek");
+ if(seekIter != itemProperties.end()) {
+ unsigned long long lseek = strtoull(seekIter->second.c_str(), NULL, 0);
+ seek = static_cast<unsigned int>(lseek);
+ if (static_cast<unsigned long long>(seek) != lseek) {
+ XdmfError::message(XdmfError::FATAL,
+ "Seek offset is too large for unsigned int");
+ }
+ }
+
+ const std::string binaryPath = getFullHeavyDataPath(contentVals[contentIndex],
+ itemProperties);
+
+ // Parse dimensions from the content
+ std::vector<unsigned int> contentStarts;
+ std::vector<unsigned int> contentStrides;
+ std::vector<unsigned int> contentDims;
+ std::vector<unsigned int> contentDataspaces;
+ if (contentVals.size() > contentIndex+1) {
+ // This is the string that contains the dimensions
+ std::string dataspaceDescription = contentVals[contentIndex+1];
+ std::vector<std::string> dataspaceVector;
+ size_t colonSplit = 0;
+ while (colonSplit != std::string::npos) {
+ colonSplit = 0;
+ colonSplit = dataspaceDescription.find_first_of(":", colonSplit);
+ if (colonSplit == std::string::npos) {
+ subcontent = dataspaceDescription;
+ }
+ else {
+ subcontent = dataspaceDescription.substr(0, colonSplit);
+ dataspaceDescription = dataspaceDescription.substr(colonSplit+1);
+ colonSplit++;
+ }
+ dataspaceVector.push_back(subcontent);
+ }
+
+ // split the description based on tokens
+ boost::tokenizer<> dimtokens(std::string(""));
+ if (dataspaceVector.size() == 1) {
+ dimtokens = boost::tokenizer<>(dataspaceDescription);
+ }
+ else if (dataspaceVector.size() == 5) {
+ dimtokens = boost::tokenizer<>(dataspaceVector[3]);
+ }
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentDims.push_back(atoi((*iter).c_str()));
+ }
+
+ if (dataspaceVector.size() == 5) {
+ unsigned long long lseek = strtoull
+ (dataspaceVector[0].c_str(), NULL, 0);
+ seek = static_cast<unsigned int>(lseek);
+ if (static_cast<unsigned long long>(seek) != lseek) {
+ XdmfError::message(XdmfError::FATAL,
+ "Seek offset is too large for unsigned int");
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[1]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentStarts.push_back(atoi((*iter).c_str()));
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[2]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentStrides.push_back(atoi((*iter).c_str()));
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[4]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentDataspaces.push_back(atoi((*iter).c_str()));
+ }
+ }
+
+ contentStep = 2;
+ // If this works then the dimension content should be skipped over
+ }
+ else {
+ // If it fails then it means that the next content is not a dimension string
+ // In this case it is assumed that the controller will have
+ // dimensions equal to the array
+ for (unsigned int j = 0; j < dimVector.size(); ++j) {
+ contentDims.push_back(dimVector[j]);
+ }
+ contentStep = 1;
+ }
+ if (contentDataspaces.size() == 0) {
+ returnControllers.push_back(XdmfBinaryController::New(binaryPath,
+ arrayType,
+ endian,
+ seek,
+ contentDims));
+ }
+ else {
+ returnControllers.push_back(
+ XdmfBinaryController::New(binaryPath,
+ arrayType,
+ endian,
+ seek,
+ contentStarts,
+ contentStrides,
+ contentDims,
+ contentDataspaces)
+ );
+ }
+ contentIndex+=contentStep;
+ }
+ }
+ else if(formatVal.compare("HDF") == 0) {
+ contentIndex = 0;
+ int contentStep = 2;
+ while (contentIndex < contentVals.size()) {
+ size_t colonLocation = contentVals[contentIndex].find(":");
+ if(colonLocation == std::string::npos) {
+ XdmfError::message(XdmfError::FATAL,
+ "':' not found in content generateHeavyControllers in "
+ "XdmfCoreItemFactory -- double check an HDF5 "
+ "data set is specified for the file");
+ }
+
+ std::string hdf5Path =
+ contentVals[contentIndex].substr(0, colonLocation);
+ std::string dataSetPath =
+ contentVals[contentIndex].substr(colonLocation+1);
+
+ hdf5Path = getFullHeavyDataPath(hdf5Path,
+ itemProperties);
+
+ // Parse dimensions from the content
+ std::vector<unsigned int> contentStarts;
+ std::vector<unsigned int> contentStrides;
+ std::vector<unsigned int> contentDims;
+ std::vector<unsigned int> contentDataspaces;
+ if (contentVals.size() > contentIndex+1) {
+ // This is the string that contains the dimensions
+ std::string dataspaceDescription = contentVals[contentIndex+1];
+ std::vector<std::string> dataspaceVector;
+ size_t colonSplit = 0;
+ while (colonSplit != std::string::npos) {
+ colonSplit = 0;
+ colonSplit = dataspaceDescription.find_first_of(":", colonSplit);
+ if (colonSplit == std::string::npos) {
+ subcontent = dataspaceDescription;
+ }
+ else {
+ subcontent = dataspaceDescription.substr(0, colonSplit);
+ dataspaceDescription = dataspaceDescription.substr(colonSplit+1);
+ colonSplit++;
+ }
+ dataspaceVector.push_back(subcontent);
+ }
+
+ // split the description based on tokens
+ boost::tokenizer<> dimtokens(std::string(""));
+ if (dataspaceVector.size() == 1) {
+ dimtokens = boost::tokenizer<>(dataspaceDescription);
+ }
+ else if (dataspaceVector.size() == 4) {
+ dimtokens = boost::tokenizer<>(dataspaceVector[2]);
+ }
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentDims.push_back(atoi((*iter).c_str()));
+ }
+
+ if (dataspaceVector.size() == 4) {
+ dimtokens = boost::tokenizer<>(dataspaceVector[0]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentStarts.push_back(atoi((*iter).c_str()));
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[1]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentStrides.push_back(atoi((*iter).c_str()));
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[3]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentDataspaces.push_back(atoi((*iter).c_str()));
+ }
+ }
+
+ contentStep = 2;
+ // If this works then the dimension content should be skipped over
+ }
+ else {
+ // If it fails then it means that the next content is not a dimension string
+ // In this case it is assumed that the controller will have
+ // dimensions equal to the array
+ for (unsigned int j = 0; j < dimVector.size(); ++j) {
+ contentDims.push_back(dimVector[j]);
+ }
+ contentStep = 1;
+ }
+ if (contentDataspaces.size() == 0) {
+ returnControllers.push_back(
+ XdmfHDF5Controller::New(hdf5Path,
+ dataSetPath,
+ arrayType,
+ std::vector<unsigned int>(contentDims.size(),
+ 0),
+ std::vector<unsigned int>(contentDims.size(),
+ 1),
+ contentDims,
+ contentDims)
+ );
+ }
+ else {
+ returnControllers.push_back(
+ XdmfHDF5Controller::New(hdf5Path,
+ dataSetPath,
+ arrayType,
+ contentStarts,
+ contentStrides,
+ contentDims,
+ contentDataspaces)
+ );
+ }
+ contentIndex+=contentStep;
+ }
+ }
+#ifdef XDMF_BUILD_TIFF
+ else if(formatVal.compare("TIFF") == 0) {
+ contentIndex = 0;
+ int contentStep = 2;
+ while (contentIndex < contentVals.size()) {
+ const std::string tiffPath = getFullHeavyDataPath(contentVals[contentIndex],
+ itemProperties);
+
+ // Parse dimensions from the content
+ std::vector<unsigned int> contentStarts;
+ std::vector<unsigned int> contentStrides;
+ std::vector<unsigned int> contentDims;
+ std::vector<unsigned int> contentDataspaces;
+ if (contentVals.size() > contentIndex+1) {
+ // This is the string that contains the dimensions
+ std::string dataspaceDescription = contentVals[contentIndex+1];
+ std::vector<std::string> dataspaceVector;
+ size_t colonSplit = 0;
+ while (colonSplit != std::string::npos) {
+ colonSplit = 0;
+ colonSplit = dataspaceDescription.find_first_of(":", colonSplit);
+ if (colonSplit == std::string::npos) {
+ subcontent = dataspaceDescription;
+ }
+ else {
+ subcontent = dataspaceDescription.substr(0, colonSplit);
+ dataspaceDescription = dataspaceDescription.substr(colonSplit+1);
+ colonSplit++;
+ }
+ dataspaceVector.push_back(subcontent);
+ }
+
+ // split the description based on tokens
+ boost::tokenizer<> dimtokens(std::string(""));
+ if (dataspaceVector.size() == 1) {
+ dimtokens = boost::tokenizer<>(dataspaceDescription);
+ }
+ else if (dataspaceVector.size() == 4) {
+ dimtokens = boost::tokenizer<>(dataspaceVector[2]);
+ }
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentDims.push_back(atoi((*iter).c_str()));
+ }
+
+ if (dataspaceVector.size() == 4) {
+ dimtokens = boost::tokenizer<>(dataspaceVector[0]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentStarts.push_back(atoi((*iter).c_str()));
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[1]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentStrides.push_back(atoi((*iter).c_str()));
+ }
+ dimtokens = boost::tokenizer<>(dataspaceVector[3]);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ contentDataspaces.push_back(atoi((*iter).c_str()));
+ }
+ }
+
+ contentStep = 2;
+ // If this works then the dimension content should be skipped over
+ }
+ else {
+ // If it fails then it means that the next content is not a dimension string
+ // In this case it is assumed that the controller will have
+ // dimensions equal to the array
+ for (unsigned int j = 0; j < dimVector.size(); ++j) {
+ contentDims.push_back(dimVector[j]);
+ }
+ contentStep = 1;
+ }
+ if (contentDataspaces.size() == 0) {
+ returnControllers.push_back(
+ XdmfTIFFController::New(tiffPath,
+ arrayType,
+ std::vector<unsigned int>(contentDims.size(),
+ 0),
+ std::vector<unsigned int>(contentDims.size(),
+ 1),
+ contentDims,
+ contentDims)
+ );
+ }
+ else {
+ returnControllers.push_back(
+ XdmfTIFFController::New(tiffPath,
+ arrayType,
+ contentStarts,
+ contentStrides,
+ contentDims,
+ contentDataspaces)
+ );
+ }
+ contentIndex+=contentStep;
+ }
+ }
+#endif /* XDMF_BUILD_TIFF */
+
+ return returnControllers;
+}
+
+shared_ptr<XdmfHeavyDataWriter>
+XdmfCoreItemFactory::generateHeavyDataWriter(std::string typeName, std::string path) const
+{
+ if (typeName.compare("HDF") == 0) {
+ return XdmfHDF5Writer::New(path);
+ }
+ return shared_ptr<XdmfHeavyDataWriter>();
+}
+
+bool
+XdmfCoreItemFactory::isArrayTag(char * tag) const
+{
+ if (XdmfArray::ItemTag.compare(tag) == 0 ||
+ strcmp("DataStructure", tag) == 0 ||
+ XdmfFunction::ItemTag.compare(tag) == 0 ||
+ XdmfSubset::ItemTag.compare(tag) == 0) {
+ return true;
+ }
+ return false;
+}
+
+XdmfItem *
+XdmfCoreItemFactory::DuplicatePointer(shared_ptr<XdmfItem> original) const
+{
+ if (original->getItemTag() == XdmfArray::ItemTag) {
+ return (XdmfItem *)(new XdmfArray(*((XdmfArray *)original.get())));
+ }
+ else if (original->getItemTag() == XdmfInformation::ItemTag) {
+ return (XdmfItem *)(new XdmfInformation(*((XdmfInformation *)original.get())));
+ }
+ else if (original->getItemTag() == XdmfFunction::ItemTag) {
+ return (XdmfItem *)(new XdmfFunction(*((XdmfFunction *)original.get())));
+ }
+ else if (original->getItemTag() == XdmfSubset::ItemTag) {
+ return (XdmfItem *)(new XdmfSubset(*((XdmfSubset *)original.get())));
+ }
+ else if (original->getItemTag() == XdmfSparseMatrix::ItemTag) {
+ return (XdmfItem *)(new XdmfSparseMatrix(*((XdmfSparseMatrix *)original.get())));
+ }
+ else {
+ return NULL;
+ }
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCoreItemFactory.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFCOREITEMFACTORY_HPP_
+#define XDMFCOREITEMFACTORY_HPP_
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfItem;
+
+// Includes
+#include <map>
+#include <vector>
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief Factory that constructs XdmfItems using tags and properties.
+ *
+ * XdmfCoreItemFactory is an abstract base class.
+ */
+class XDMFCORE_EXPORT XdmfCoreItemFactory {
+
+public:
+
+ virtual ~XdmfCoreItemFactory() = 0;
+
+ /**
+ * Create a new XdmfItem.
+ *
+ * Example of use:
+ *
+ * @dontinclude ExampleXdmfCoreItemFactory.cpp
+ * @skipline //#createItem
+ * @until //#createItem
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCoreItemFactory.py
+ * @skipline #//createItem
+ * @until #//createItem
+ *
+ * @param itemTag A string containing the tag of the XdmfItem to create.
+ * @param itemProperties A map of key/value properties for the the XdmfItem.
+ * @param childItems The children of the XdmfItem to create.
+ *
+ * @return Constructed XdmfItem. If no XdmfItem can be constructed,
+ * return NULL.
+ */
+ virtual shared_ptr<XdmfItem>
+ createItem(const std::string & itemTag,
+ const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems) const;
+
+ virtual std::vector<shared_ptr<XdmfHeavyDataController> >
+ generateHeavyDataControllers(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<unsigned int> & passedDimensions = std::vector<unsigned int>(),
+ shared_ptr<const XdmfArrayType> passedArrayType = shared_ptr<const XdmfArrayType>(),
+ const std::string & passedFormat = std::string()) const;
+
+ virtual shared_ptr<XdmfHeavyDataWriter>
+ generateHeavyDataWriter(std::string typeName, std::string path) const;
+
+ virtual bool isArrayTag(char * tag) const;
+
+ /**
+ * Extracts the pointer from the provided shared pointer. Primarily used for C interface.
+ *
+ * @param original The source shared pointer that the pointer will be pulled from.
+ * @return A duplicate of the object contained in the pointer.
+ */
+ virtual XdmfItem *
+ DuplicatePointer(shared_ptr<XdmfItem> original) const;
+
+protected:
+
+ shared_ptr<const XdmfArrayType>
+ getArrayType(const std::map<std::string, std::string> & itemProperties) const;
+
+ std::string
+ getFullHeavyDataPath(const std::string & filePath,
+ const std::map<std::string, std::string> & itemProperties) const;
+
+ XdmfCoreItemFactory();
+
+private:
+
+ XdmfCoreItemFactory(const XdmfCoreItemFactory &); // Not implemented.
+ void operator=(const XdmfCoreItemFactory &); // Not implemented.
+
+};
+
+#endif
+
+#endif /* XDMFCOREITEMFACTORY_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCoreReader.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <boost/algorithm/string/trim.hpp>
+#include <boost/tokenizer.hpp>
+#include <cstring>
+#include <map>
+#include <sstream>
+#include <utility>
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfCoreItemFactory.hpp"
+#include "XdmfCoreReader.hpp"
+#include "XdmfError.hpp"
+#include "XdmfFunction.hpp"
+#include "XdmfSubset.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfSystemUtils.hpp"
+
+/**
+ * PIMPL
+ */
+class XdmfCoreReader::XdmfCoreReaderImpl {
+
+public:
+
+ XdmfCoreReaderImpl(const shared_ptr<const XdmfCoreItemFactory> itemFactory,
+ const XdmfCoreReader * const coreReader) :
+ mCoreReader(coreReader),
+ mItemFactory(itemFactory)
+ {
+ };
+
+ ~XdmfCoreReaderImpl()
+ {
+ };
+
+ void
+ closeFile()
+ {
+ mXPathMap.clear();
+ xmlXPathFreeContext(mXPathContext);
+ for(std::map<std::string, xmlDocPtr>::const_iterator iter =
+ mDocuments.begin(); iter != mDocuments.end(); ++iter) {
+ xmlFreeDoc(iter->second);
+ }
+ mDocuments.clear();
+
+ xmlCleanupParser();
+ }
+
+ void
+ openFile(const std::string & filePath)
+ {
+ mXMLDir = XdmfSystemUtils::getRealPath(filePath);
+ size_t index = mXMLDir.find_last_of("/\\");
+ if(index != std::string::npos) {
+ mXMLDir = mXMLDir.substr(0, index + 1);
+ }
+
+ mDocument = xmlReadFile(filePath.c_str(), NULL, XML_PARSE_NOENT);
+
+ if(mDocument == NULL) {
+ XdmfError::message(XdmfError::FATAL,
+ "xmlReadFile could not read " + filePath +
+ " in XdmfCoreReader::XdmfCoreReaderImpl::openFile");
+ }
+
+ mDocuments.insert(std::make_pair((char*)mDocument->URL, mDocument));
+
+ mXPathContext = xmlXPtrNewContext(mDocument, NULL, NULL);
+ mXPathMap.clear();
+ }
+
+ void
+ parse(const std::string & lightData)
+ {
+ mDocument = xmlParseDoc((const xmlChar*)lightData.c_str());
+
+ if(mDocument == NULL) {
+ XdmfError::message(XdmfError::FATAL,
+ "xmlReadFile could not parse passed light data string"
+ " in XdmfCoreReader::XdmfCoreReaderImpl::parse");
+ }
+
+ //mDocuments.insert(std::make_pair((char*)mDocument->URL, mDocument));
+ mXPathContext = xmlXPtrNewContext(mDocument, NULL, NULL);
+ mXPathMap.clear();
+ }
+
+ /**
+ * Constructs XdmfItems for all nodes in currNode's tree.
+ * XdmfItems are constructed by recursively calling this function for all
+ * children of currNode.
+ */
+ std::vector<shared_ptr<XdmfItem> >
+ read(xmlNodePtr currNode)
+ {
+ std::vector<shared_ptr<XdmfItem> > myItems;
+
+ while(currNode != NULL) {
+ if(currNode->type == XML_ELEMENT_NODE) {
+ // Normal reading
+ this->readSingleNode(currNode, myItems);
+ }
+ currNode = currNode->next;
+ }
+ return myItems;
+ }
+
+ /**
+ * Reads a single xmlNode into an XdmfItem object in memory. The constructed
+ * XdmfItem is added to myItems and an entry is added mapping the xmlNodePtr
+ * to the new XdmfItem in the mXPathMap.
+ */
+ void
+ readSingleNode(const xmlNodePtr currNode,
+ std::vector<shared_ptr<XdmfItem> > & myItems)
+ {
+ // Deal with proper resolution of XIncludes
+ if(xmlStrcmp(currNode->name, (xmlChar*)"include") == 0) {
+
+ xmlChar * xpointer = NULL;
+ xmlChar * href = NULL;
+
+ xmlAttrPtr currAttribute = currNode->properties;
+ while(currAttribute != NULL) {
+ if(xmlStrcmp(currAttribute->name, (xmlChar*)"xpointer") == 0) {
+ xpointer = currAttribute->children->content;
+ }
+ if(xmlStrcmp(currAttribute->name, (xmlChar*)"href") == 0) {
+ href = currAttribute->children->content;
+ }
+ currAttribute = currAttribute->next;
+ }
+
+ xmlXPathContextPtr oldContext = mXPathContext;
+ if(href) {
+ xmlDocPtr document;
+ xmlChar * filePath = xmlBuildURI(href, mDocument->URL);
+ std::map<std::string, xmlDocPtr>::const_iterator iter =
+ mDocuments.find((char*)filePath);
+ if(iter == mDocuments.end()) {
+ document = xmlReadFile((char*)filePath, NULL, 0);
+ mDocuments.insert(std::make_pair((char*)document->URL,
+ document));
+ }
+ else {
+ document = iter->second;
+ }
+
+ mXPathContext = xmlXPtrNewContext(document, NULL, NULL);
+ }
+
+ if(xpointer) {
+ xmlXPathObjectPtr result = xmlXPtrEval(xpointer, mXPathContext);
+ if(result && !xmlXPathNodeSetIsEmpty(result->nodesetval)) {
+ for(int i=0; i<result->nodesetval->nodeNr; ++i) {
+ this->readSingleNode(result->nodesetval->nodeTab[i],
+ myItems);
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Invalid xpointer encountered.");
+ }
+ xmlXPathFreeObject(result);
+ }
+
+ if(href) {
+ xmlXPathFreeContext(mXPathContext);
+ }
+
+ mXPathContext = oldContext;
+
+ }
+ else {
+
+ // Check to see if the node is already in the XPath Map (seen previously)
+ std::map<xmlNodePtr, shared_ptr<XdmfItem> >::const_iterator iter =
+ mXPathMap.find(currNode);
+ // If it is grab it from the previously stored items
+ if(iter != mXPathMap.end()) {
+ myItems.push_back(iter->second);
+ }
+ else {
+ // Otherwise, generate a new XdmfItem from the node
+ std::map<std::string, std::string> itemProperties;
+
+ xmlNodePtr childNode = currNode->children;
+ // generate content if an array or arrayReference
+ if (mItemFactory->isArrayTag((char *)currNode->name)) {
+ while(childNode != NULL) {
+ if(childNode->type == XML_TEXT_NODE && childNode->content) {
+ const char * content = (char*)childNode->content;
+
+ // Determine if content is whitespace
+ bool whitespace = true;
+
+ const char * contentPtr = content;
+ // Step through to end of pointer
+ while(contentPtr != NULL) {
+ // If not a whitespace character, break
+ if(!isspace(*contentPtr++)) {
+ whitespace = false;
+ break;
+ }
+ }
+ if(!whitespace) {
+ std::string contentString(content);
+ boost::algorithm::trim(contentString);
+ itemProperties.insert(std::make_pair("Content", contentString));
+ itemProperties.insert(std::make_pair("XMLDir", mXMLDir));
+ break;
+ }
+ }
+ childNode = childNode->next;
+ }
+ }
+
+ // Pull attributes from node
+ xmlAttrPtr currAttribute = currNode->properties;
+ while(currAttribute != NULL) {
+ itemProperties.insert(std::make_pair((char *)currAttribute->name,
+ (char *)currAttribute->children->content));
+ currAttribute = currAttribute->next;
+ }
+
+ // Build XdmfItem
+ const std::vector<shared_ptr<XdmfItem> > childItems =
+ this->read(currNode->children);
+ shared_ptr<XdmfItem> newItem =
+ mItemFactory->createItem((const char *)currNode->name,
+ itemProperties,
+ childItems);
+
+ if(newItem == NULL) {
+ XdmfError::message(XdmfError::FATAL,
+ "mItemFactory failed to createItem in "
+ "XdmfCoreReader::XdmfCoreReaderImpl::readSingleNode");
+ }
+
+
+ // Populate built XdmfItem
+ newItem->populateItem(itemProperties,
+ childItems,
+ mCoreReader);
+
+ myItems.push_back(newItem);
+ mXPathMap.insert(std::make_pair(currNode, newItem));
+ }
+ }
+ }
+
+ void
+ readPathObjects(const std::string & xPath,
+ std::vector<shared_ptr<XdmfItem> > & myItems)
+ {
+ xmlXPathObjectPtr xPathObject =
+ xmlXPathEvalExpression((xmlChar*)xPath.c_str(), mXPathContext);
+ if(xPathObject && xPathObject->nodesetval) {
+ for(int i=0; i<xPathObject->nodesetval->nodeNr; ++i) {
+ this->readSingleNode(xPathObject->nodesetval->nodeTab[i], myItems);
+ }
+ }
+ xmlXPathFreeObject(xPathObject);
+ }
+
+ xmlDocPtr mDocument;
+ std::map<std::string, xmlDocPtr> mDocuments;
+ const XdmfCoreReader * const mCoreReader;
+ const shared_ptr<const XdmfCoreItemFactory> mItemFactory;
+ std::string mXMLDir;
+ xmlXPathContextPtr mXPathContext;
+ std::map<xmlNodePtr, shared_ptr<XdmfItem> > mXPathMap;
+};
+
+XdmfCoreReader::XdmfCoreReader(const shared_ptr<const XdmfCoreItemFactory> itemFactory) :
+ mImpl(new XdmfCoreReaderImpl(itemFactory, this))
+{
+}
+
+XdmfCoreReader::~XdmfCoreReader()
+{
+ delete mImpl;
+}
+
+XdmfItem *
+XdmfCoreReader::DuplicatePointer(shared_ptr<XdmfItem> original) const
+{
+ if (mImpl == NULL) {
+ XdmfError::message(XdmfError::FATAL, "Error: Reader Internal Object is NULL");
+ }
+ return mImpl->mItemFactory->DuplicatePointer(original);
+}
+
+std::vector<shared_ptr<XdmfHeavyDataController> >
+XdmfCoreReader::generateHeavyDataControllers(std::map<std::string, std::string> controllerProperties,
+ const std::vector<unsigned int> & passedDimensions,
+ shared_ptr<const XdmfArrayType> passedArrayType,
+ const std::string & passedFormat) const
+{
+ return mImpl->mItemFactory->generateHeavyDataControllers(controllerProperties,
+ passedDimensions,
+ passedArrayType,
+ passedFormat);
+}
+
+shared_ptr<XdmfHeavyDataWriter>
+XdmfCoreReader::generateHeavyDataWriter(std::string typeName, std::string path) const
+{
+ return mImpl->mItemFactory->generateHeavyDataWriter(typeName, path);
+}
+
+shared_ptr<XdmfItem >
+XdmfCoreReader::parse(const std::string & lightData) const
+{
+ mImpl->parse(lightData);
+ const xmlNodePtr currNode = xmlDocGetRootElement(mImpl->mDocument);
+ std::vector<shared_ptr<XdmfItem> > toReturn;
+ if(mImpl->mItemFactory->createItem((const char*)currNode->name,
+ std::map<std::string, std::string>(),
+ std::vector<shared_ptr<XdmfItem> >()) == NULL) {
+ toReturn = mImpl->read(currNode->children);
+ }
+ else {
+ toReturn = mImpl->read(currNode);
+ }
+ mImpl->closeFile();
+ return(toReturn[0]);
+}
+
+std::vector<shared_ptr<XdmfItem> >
+XdmfCoreReader::readItems(const std::string & filePath) const
+{
+ mImpl->openFile(filePath);
+ const xmlNodePtr currNode = xmlDocGetRootElement(mImpl->mDocument);
+ const std::vector<shared_ptr<XdmfItem> > toReturn =
+ mImpl->read(currNode->children);
+ mImpl->closeFile();
+ return toReturn;
+}
+
+shared_ptr<XdmfItem>
+XdmfCoreReader::read(const std::string & filePath) const
+{
+ const std::vector<shared_ptr<XdmfItem> > toReturn = readItems(filePath);
+ if (toReturn.size() == 0) {
+ return(shared_ptr<XdmfItem>());
+ }
+ return(toReturn[0]);
+}
+
+std::vector<shared_ptr<XdmfItem> >
+XdmfCoreReader::read(const std::string & filePath,
+ const std::string & xPath) const
+{
+ mImpl->openFile(filePath);
+ std::vector<shared_ptr<XdmfItem> > toReturn = this->readPathObjects(xPath);
+ mImpl->closeFile();
+ return toReturn;
+}
+
+std::vector<shared_ptr<XdmfItem> >
+XdmfCoreReader::readPathObjects(const std::string & xPath) const
+{
+ std::vector<shared_ptr<XdmfItem> > toReturn;
+ mImpl->readPathObjects(xPath, toReturn);
+ return toReturn;
+}
+
+// C Wrappers
+
+XDMFITEM *
+XdmfCoreReaderRead(XDMFCOREREADER * reader, char * filePath, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<XdmfItem> returnItem = ((XdmfCoreReader *)reader)->read(filePath);
+ return (XDMFITEM *)((void *)((XdmfItem *)((XdmfCoreReader *)reader)->DuplicatePointer(returnItem)));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfCoreReader.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFCOREREADER_HPP_
+#define XDMFCOREREADER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+#include "XdmfItem.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfCoreItemFactory;
+
+// Includes
+#include <string>
+#include <vector>
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief Reads an Xdmf file stored on disk into memory.
+ *
+ * Reads an Xdmf file stored on disk into an Xdmf structure in memory.
+ * All light data is parsed in order to create appropriate Xdmf
+ * objects. Heavy data controllers are created and attached to
+ * XdmfArrays but no heavy data is read into memory.
+ *
+ * XdmfCoreReader is an abstract base class.
+ */
+class XDMFCORE_EXPORT XdmfCoreReader {
+
+public:
+
+ virtual ~XdmfCoreReader() = 0;
+
+ /**
+ * Uses the internal item factory to create a copy of the internal pointer
+ * of the provided shared pointer. Primarily used for C wrapping.
+ *
+ * @param original The source shared pointer that the pointer will be pulled from.
+ * @return A duplicate of the object contained in the pointer.
+ */
+ virtual XdmfItem * DuplicatePointer(shared_ptr<XdmfItem> original) const;
+
+ virtual std::vector<shared_ptr<XdmfHeavyDataController> >
+ generateHeavyDataControllers(std::map<std::string, std::string> controllerProperties,
+ const std::vector<unsigned int> & passedDimensions = std::vector<unsigned int>(),
+ shared_ptr<const XdmfArrayType> passedArrayType = shared_ptr<const XdmfArrayType>(),
+ const std::string & passedFormat = std::string()) const;
+
+ virtual shared_ptr<XdmfHeavyDataWriter>
+ generateHeavyDataWriter(std::string typeName, std::string path) const;
+
+ /**
+ * Parse a string containing light data into an Xdmf structure in
+ * memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCoreReader.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#parse
+ * @until //#parse
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCoreReader.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//parse
+ * @until #//parse
+ *
+ * @param lightData A string containing light data description of an
+ * Xdmf file.
+ *
+ * @return An XdmfItem at the root of the Xdmf tree.
+ */
+ virtual shared_ptr<XdmfItem> parse(const std::string & lightData) const;
+
+ /**
+ * Read an Xdmf file from disk into memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCoreReader.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#readpath
+ * @until //#readpath
+ * @skipline //#readroot
+ * @until //#readroot
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCoreReader.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//readpath
+ * @until #//readpath
+ * @skipline #//readroot
+ * @until #//readroot
+ *
+ * @param filePath The path of the Xdmf file to read in from disk.
+ *
+ * @return An XdmfItem at the root of the Xdmf tree.
+ */
+ virtual shared_ptr<XdmfItem> read(const std::string & filePath) const;
+
+ /**
+ * Read part of an Xdmf file from disk into memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCoreReader.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#readpath
+ * @until //#readpath
+ * @skipline //#readXPath
+ * @until //#readXPath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCoreReader.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//readpath
+ * @until #//readpath
+ * @skipline #//readXPath
+ * @until #//readXPath
+ *
+ * @param filePath The path of the Xdmf file to read in from disk.
+ * @param xPath An XPath corresponding to the portion of the
+ * file to read.
+ *
+ * @return A vector of XdmfItems that are included
+ * in the XPath.
+ */
+ virtual std::vector<shared_ptr<XdmfItem> >
+ read(const std::string & filePath,
+ const std::string & xPath) const;
+
+ /**
+ * Read an Xdmf file from disk into memory.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfCoreReader.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#readpath
+ * @until //#readpath
+ * @skipline //#readItems
+ * @until //#readItems
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleCoreReader.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//readpath
+ * @until #//readpath
+ * @skipline #//readItems
+ * @until #//readItems
+ *
+ * @param filePath The path of the Xdmf file to read in from disk.
+ *
+ * @return A vector of XdmfItems at the root of the Xdmf tree.
+ */
+ virtual std::vector<shared_ptr<XdmfItem> >
+ readItems(const std::string & filePath) const;
+
+ /**
+ * Used by the other functions to read items from an open file.
+ *
+ * Since files are closed between reads, this does nothing by itself.
+ *
+ * @param xPath An XPath corresponding to the portion of the file to read.
+ *
+ * @return A vector of items at the X path provided.
+ */
+ std::vector<shared_ptr<XdmfItem> >
+ readPathObjects(const std::string & xPath) const;
+
+protected:
+
+ /**
+ * Constructor
+ *
+ * @param itemFactory an XdmfCoreItemFactory to construct XdmfItems
+ * for a specific language.
+ */
+ XdmfCoreReader(const shared_ptr<const XdmfCoreItemFactory> itemFactory);
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfCoreReaderImpl;
+
+ XdmfCoreReader(const XdmfCoreReader &); // Not implemented.
+ void operator=(const XdmfCoreReader &); // Not implemented.
+
+ XdmfCoreReaderImpl * const mImpl;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFCOREREADER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFCOREREADER XDMFCOREREADER;
+
+XDMFCORE_EXPORT XDMFITEM * XdmfCoreReaderRead(XDMFCOREREADER * reader, char * filePath, int * status);
+
+#define XDMF_CORE_READER_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT XDMFITEM * ClassName##Read( CClassName * reader, char * filePath, int * status);
+
+#define XDMF_CORE_READER_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+XDMFITEM * ClassName##Read( CClassName * reader, char * filePath, int * status) \
+{ \
+ return XdmfCoreReaderRead((XDMFCOREREADER *)((void *)reader), filePath, status); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFCOREREADER_HPP_ */
--- /dev/null
+#include <XdmfError.hpp>
+#include <cstdlib>
+#include <iostream>
+
+XdmfError::XdmfError(Level level, std::string message) :
+ mLevel(level),
+ mMessage(message)
+{
+}
+
+XdmfError::~XdmfError() throw()
+{
+}
+
+/************************
+ *** Public Functions ***
+ ************************/
+
+XdmfError::Level
+XdmfError::getLevel() const
+{
+ return XdmfError::mLevel;
+}
+
+void
+XdmfError::setLevel(Level l)
+{
+ XdmfError::mLevel = l;
+}
+
+const char *
+XdmfError::what() const throw()
+{
+ return XdmfError::mMessage.c_str();
+}
+
+/*******************************
+ *** Public Static Functions ***
+ *******************************/
+
+bool
+XdmfError::getCErrorsAreFatal()
+{
+ return XdmfError::mCErrorsAreFatal;
+}
+
+XdmfError::Level
+XdmfError::getLevelLimit()
+{
+ return XdmfError::mLevelLimit;
+}
+
+XdmfError::Level
+XdmfError::getSuppressionLevel()
+{
+ return XdmfError::mSuppressLevel;
+}
+
+void
+XdmfError::setCErrorsAreFatal(bool status)
+{
+ XdmfError::mCErrorsAreFatal = status;
+}
+
+void
+XdmfError::setLevelLimit(Level l)
+{
+ XdmfError::mLevelLimit = l;
+}
+
+void
+XdmfError::setSuppressionLevel(Level l)
+{
+ XdmfError::mSuppressLevel = l;
+}
+
+void
+XdmfError::message(Level level, std::string msg)
+{
+ if (level<=XdmfError::getSuppressionLevel())
+ {
+ XdmfError::WriteToStream(msg);
+ }
+ if(level<=XdmfError::getLevelLimit()) {
+ throw XdmfError(level, msg);
+ }
+}
+
+void
+XdmfError::setBuffer(std::streambuf* buf)
+{
+ XdmfError::mBuf = buf;
+}
+
+/********************************
+ *** Private Static Functions ***
+ ********************************/
+
+// automatically writes the message to the provided buffer
+// by default this is basically a print statement
+void
+XdmfError::WriteToStream(std::string msg)
+{
+ if(msg[msg.length()-1] != '\n') {
+ // using \r\n for windows compatiblity
+ msg+="\r\n";
+ }
+ XdmfError::mBuf->sputn(msg.c_str(),msg.length());
+}
+
+/******************************************
+ *** Initialize Static Member Variables ***
+ ******************************************/
+
+XdmfError::Level XdmfError::mLevelLimit = XdmfError::FATAL;
+XdmfError::Level XdmfError::mSuppressLevel = XdmfError::WARNING;
+std::streambuf* XdmfError::mBuf=std::cout.rdbuf();
+bool XdmfError::mCErrorsAreFatal = false;
+
+// C Wrappers
+
+void XdmfErrorSetCErrorsAreFatal(int status)
+{
+ XdmfError::setCErrorsAreFatal(status);
+}
+
+void XdmfErrorSetLevelLimit(int level, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (level) {
+ case XDMF_ERROR_FATAL:
+ XdmfError::setLevelLimit(XdmfError::FATAL);
+ break;
+ case XDMF_ERROR_WARNING:
+ XdmfError::setLevelLimit(XdmfError::WARNING);
+ break;
+ case XDMF_ERROR_DEBUG:
+ XdmfError::setLevelLimit(XdmfError::DEBUG);
+ break;
+ default:
+ try {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Error Level");
+ }
+ catch (XdmfError & e) {
+ throw e;
+ }
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfErrorSetSuppressionLevel(int level, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (level) {
+ case XDMF_ERROR_FATAL:
+ XdmfError::setSuppressionLevel(XdmfError::FATAL);
+ break;
+ case XDMF_ERROR_WARNING:
+ XdmfError::setSuppressionLevel(XdmfError::WARNING);
+ break;
+ case XDMF_ERROR_DEBUG:
+ XdmfError::setSuppressionLevel(XdmfError::DEBUG);
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Error Level");
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+int XdmfErrorGetCErrorsAreFatal()
+{
+ return XdmfError::getCErrorsAreFatal();
+}
+
+int XdmfErrorGetLevelLimit()
+{
+ if (XdmfError::getLevelLimit() == XdmfError::FATAL) {
+ return XDMF_ERROR_FATAL;
+ }
+ else if (XdmfError::getLevelLimit() == XdmfError::WARNING) {
+ return XDMF_ERROR_WARNING;
+ }
+ else if (XdmfError::getLevelLimit() == XdmfError::DEBUG) {
+ return XDMF_ERROR_DEBUG;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Error Level");
+ }
+ return -1;
+}
+
+int XdmfErrorGetSuppressionLevel()
+{
+ if (XdmfError::getSuppressionLevel() == XdmfError::FATAL) {
+ return XDMF_ERROR_FATAL;
+ }
+ else if (XdmfError::getSuppressionLevel() == XdmfError::WARNING) {
+ return XDMF_ERROR_WARNING;
+ }
+ else if (XdmfError::getSuppressionLevel() == XdmfError::DEBUG) {
+ return XDMF_ERROR_DEBUG;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid Error Level");
+ }
+ return -1;
+}
--- /dev/null
+#ifndef XDMFERROR_HPP_
+#define XDMFERROR_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include <iosfwd>
+#include <sstream>
+#include <exception>
+
+class XDMFCORE_EXPORT XdmfError : public std::exception
+{
+public:
+ enum Level {FATAL, WARNING, DEBUG};
+
+ /**
+ * One of the constructors for XdmfError, this one doesn't print to the buffer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python:
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param level The error level of the exception being constructed
+ * @param message The message to be attached to the exception
+ */
+ XdmfError(Level level, std::string message);
+
+ ~XdmfError() throw();
+
+ /**
+ * Sets the error level of the exception.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setLevel
+ * @until //#setLevel
+ *
+ * Python:
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//setLevel
+ * @until #//setLevel
+ *
+ * @param l The new level of the exception
+ */
+ void setLevel(Level l);
+
+ /**
+ * Gets the error level of the exception.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getLevel
+ * @until //#getLevel
+ *
+ * Python:
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//getLevel
+ * @until #//getLevel
+ *
+ * @return The error level of the exception
+ */
+ Level getLevel() const;
+
+ /**
+ * Gets whether C errors are Fatal. If set to false a status will be returned
+ * to C when an error is thrown. Otherwise there will be no handling and the
+ * program will exit since C cannot handle exceptions.
+ *
+ * @param status Whether the C wrappers are to pass an integer value to
+ * C on failure instead of exiting.
+ */
+ static void setCErrorsAreFatal(bool status);
+
+ /**
+ * Sets the level limit for Errors. This determines what level of errors will be thrown with message.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setLevelLimit
+ * @until //#setLevelLimit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//setLevelLimit
+ * @until #//setLevelLimit
+ *
+ * @param l The cutoff level for sending exceptions via message
+ */
+ static void setLevelLimit(Level l);
+
+ /**
+ * Sets the minimum Error level that displays messages with the message function.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#setSuppressionLevel
+ * @until //#setSuppressionLevel
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//setSuppressionLevel
+ * @until #//setSuppressionLevel
+ *
+ * @param l The new minimum error level to display a message
+ */
+ static void setSuppressionLevel(Level l);
+
+ /**
+ * Gets whether C errors are Fatal. If set to false a status will be returned
+ * to C when an error is thrown. Otherwise there will be no handling and the
+ * program will exit since C cannot handle exceptions.
+ *
+ * @return Whether the C wrappers with pass an integer value to C
+ * instead of stopping the program
+ */
+ static bool getCErrorsAreFatal();
+
+ /**
+ * Gets the level limit for Errors.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getLevelLimit
+ * @until //#getLevelLimit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//getLevelLimit
+ * @until #//getLevelLimit
+ *
+ * @return The cuttof level for sending exceptions via message
+ */
+ static Level getLevelLimit();
+
+ /**
+ * Gets the minimum Error level that displays messages with the message function.
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#getSuppressionLevel
+ * @until //#getSuppressionLevel
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//getSuppressionLevel
+ * @until #//getSuppressionLevel
+ *
+ * @return The minimum error level to display a message
+ */
+ static Level getSuppressionLevel();
+
+ /**
+ * Alternate constructor for XdmfError exceptions.
+ * This one automatically prints out the message provided if the error level
+ * above the suppression level. If the error level is not above the
+ * level limit an exception will not be thrown.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#message
+ * @until //#message
+ *
+ * Python: Generates a RuntimeError instead of an XdmfError in Python
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//message
+ * @until #//message
+ *
+ * @param l The level of the error to be generated
+ * @param msg The message to be associated with the error generated and printed out
+ */
+ static void message(Level l, std::string msg);
+
+ /**
+ * Sets which buffer the error messages are printed to with the message function.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setBuffer
+ * @until //#setBuffer
+ *
+ * Python: Not supported in Python
+ *
+ * @param buf The buffer that the error messages will be printed to
+ */
+ static void setBuffer(std::streambuf* buf);
+
+ /**
+ * Gets the message associated with this exception.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfError.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#what
+ * @until //#what
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleError.py
+ * @skipline #//what
+ * @until #//what
+ *
+ * @return The message associated with the exception
+ */
+ virtual const char * what() const throw();
+
+private:
+ Level mLevel;
+ static Level mLevelLimit;
+ static Level mSuppressLevel;
+ static std::streambuf* mBuf;
+ static bool mCErrorsAreFatal;
+ std::string mMessage;
+
+ static void WriteToStream(std::string msg);
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#define XDMF_SUCCESS 1
+#define XDMF_FAIL -1
+
+#define XDMF_ERROR_FATAL 40
+#define XDMF_ERROR_WARNING 41
+#define XDMF_ERROR_DEBUG 42
+
+XDMFCORE_EXPORT void XdmfErrorSetCErrorsAreFatal(int status);
+
+XDMFCORE_EXPORT void XdmfErrorSetLevelLimit(int level, int * status);
+
+XDMFCORE_EXPORT void XdmfErrorSetSuppressionLevel(int level, int * status);
+
+XDMFCORE_EXPORT int XdmfErrorGetCErrorsAreFatal();
+
+XDMFCORE_EXPORT int XdmfErrorGetLevelLimit();
+
+XDMFCORE_EXPORT int XdmfErrorGetSuppressionLevel();
+
+#ifdef __cplusplus
+
+//Use these macros to catch Exceptions for C code
+
+#define XDMF_ERROR_WRAP_START(status) \
+if (status) { \
+ *status = XDMF_SUCCESS; \
+} \
+try {
+
+#define XDMF_ERROR_WRAP_END(status) \
+} \
+catch (XdmfError & e) { \
+ if (XdmfError::getCErrorsAreFatal()) { \
+ throw e; \
+ } \
+ else { \
+ if (status) { \
+ *status = XDMF_FAIL; \
+ } \
+ } \
+}
+
+}
+#endif
+
+#endif /* XDMFERROR_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfFunction.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfFunction.hpp"
+#include "XdmfWriter.hpp"
+#include <stack>
+#include <cmath>
+#include <boost/assign.hpp>
+#include "XdmfError.hpp"
+
+class XdmfFunctionInternalImpl : public XdmfFunction::XdmfFunctionInternal {
+ public:
+ static shared_ptr<XdmfFunctionInternalImpl>
+ New(shared_ptr<XdmfArray> (*newInternal)(std::vector<shared_ptr<XdmfArray> >))
+ {
+ shared_ptr<XdmfFunctionInternalImpl> p (new XdmfFunctionInternalImpl(newInternal));
+ return p;
+ }
+
+ ~XdmfFunctionInternalImpl()
+ {
+ }
+
+ virtual shared_ptr<XdmfArray> execute(std::vector<shared_ptr<XdmfArray> > valueVector)
+ {
+ return (*mInternalFunction)(valueVector);
+ }
+ private:
+ XdmfFunctionInternalImpl(shared_ptr<XdmfArray> (*newInternal)(std::vector<shared_ptr<XdmfArray> >))
+ {
+ mInternalFunction = newInternal;
+ }
+
+ shared_ptr<XdmfArray> (*mInternalFunction)(std::vector<shared_ptr<XdmfArray> >);
+};
+
+class XdmfOperationInternalImpl : public XdmfFunction::XdmfOperationInternal {
+ public:
+ static shared_ptr<XdmfOperationInternalImpl>
+ New(shared_ptr<XdmfArray> (*newInternal)(shared_ptr<XdmfArray>, shared_ptr<XdmfArray>))
+ {
+ shared_ptr<XdmfOperationInternalImpl> p (new XdmfOperationInternalImpl(newInternal));
+ return p;
+ }
+
+ ~XdmfOperationInternalImpl()
+ {
+ }
+
+ virtual shared_ptr<XdmfArray> execute(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2)
+ {
+ return (*mInternalOperation)(val1, val2);
+ }
+ private:
+ XdmfOperationInternalImpl(shared_ptr<XdmfArray> (*newInternal)(shared_ptr<XdmfArray>,
+ shared_ptr<XdmfArray>))
+ {
+ mInternalOperation = newInternal;
+ }
+
+ shared_ptr<XdmfArray> (*mInternalOperation)(shared_ptr<XdmfArray>, shared_ptr<XdmfArray>);
+};
+
+std::string XdmfFunction::mSupportedOperations = "-+/*|#()";
+const std::string XdmfFunction::mValidVariableChars =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_:.";
+const std::string XdmfFunction::mValidDigitChars = "1234567890.";
+// List the priorities for the operations, based on the order of operations
+// The index of the corresponding operation in validOperationChars
+// is the same as the index of its priority in this array
+std::map<char, int> XdmfFunction::mOperationPriority =
+ boost::assign::map_list_of ('-', 4)
+ ('+', 4)
+ ('/', 3)
+ ('*', 3)
+ ('|', 2)
+ ('#', 1)
+ ('(', 0)
+ (')', 0);
+// The higher the value, the earlier the operation is
+// evaluated in the order of operations
+// With the exception of parenthesis which are evaluated
+// as soon as the closing parenthesis is found
+
+// Note, it doesn't handle overloaded functions well.
+// Will generate errors unless overload methods are typecast.
+std::map<std::string, shared_ptr<XdmfFunction::XdmfFunctionInternal> >
+ XdmfFunction::arrayFunctions =
+ boost::assign::map_list_of
+ ("ABS", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::abs))
+ ("ABS_TOKEN", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::abs))
+ ("ACOS", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::arccos))
+ ("ASIN", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::arcsin))
+ ("ATAN", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::arctan))
+ ("AVE", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::average))
+ ("COS", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::cos))
+ ("EXP", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::exponent))
+ ("JOIN", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::join))
+ ("LOG", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::log))
+ ("SIN", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::sin))
+ ("SQRT", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::sqrt))
+ ("SUM", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::sum))
+ ("TAN", XdmfFunctionInternalImpl::New((shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))
+ XdmfFunction::tan));
+
+std::map<char, shared_ptr<XdmfFunction::XdmfOperationInternal> >
+ XdmfFunction::operations =
+ boost::assign::map_list_of
+ ('-', XdmfOperationInternalImpl::New(XdmfFunction::subtraction))
+ ('+', XdmfOperationInternalImpl::New(XdmfFunction::addition))
+ ('*', XdmfOperationInternalImpl::New(XdmfFunction::multiplication))
+ ('/', XdmfOperationInternalImpl::New(XdmfFunction::division))
+ ('|', XdmfOperationInternalImpl::New(XdmfFunction::chunk))
+ ('#', XdmfOperationInternalImpl::New(XdmfFunction::interlace));
+
+shared_ptr<XdmfFunction>
+XdmfFunction::New()
+{
+ shared_ptr<XdmfFunction> p(new XdmfFunction());
+ return p;
+}
+
+shared_ptr<XdmfFunction>
+XdmfFunction::New(std::string newExpression,
+ std::map<std::string, shared_ptr<XdmfArray> > newVariables)
+{
+ shared_ptr<XdmfFunction> p(new XdmfFunction(newExpression, newVariables));
+ return p;
+}
+
+XdmfFunction::XdmfFunction():
+ mExpression("")
+{
+}
+
+XdmfFunction::XdmfFunction(std::string newExpression,
+ std::map<std::string, shared_ptr<XdmfArray> > newVariables):
+ mVariableList(newVariables),
+ mExpression(newExpression)
+{
+}
+
+XdmfFunction::XdmfFunction(XdmfFunction & refFunction) :
+ XdmfArrayReference(refFunction),
+ mExpression(refFunction.getExpression())
+{
+ std::vector<std::string> copyVariables = refFunction.getVariableList();
+ for (unsigned int i = 0; i < copyVariables.size(); ++i) {
+ mVariableList[copyVariables[i]] = refFunction.getVariable(copyVariables[i]);
+ }
+}
+
+XdmfFunction::~XdmfFunction()
+{
+}
+
+const std::string XdmfFunction::ItemTag = "Function";
+
+shared_ptr<XdmfArray>
+XdmfFunction::abs(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function abs");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(std::abs(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+int
+XdmfFunction::addFunction(std::string name,
+ shared_ptr<XdmfArray>(*functionref)(std::vector<shared_ptr<XdmfArray> >))
+{
+ shared_ptr<XdmfFunctionInternalImpl> newFunction =
+ XdmfFunctionInternalImpl::New(functionref);
+ return XdmfFunction::addFunction(name, newFunction);
+}
+
+int
+XdmfFunction::addFunction(std::string name,
+ shared_ptr<XdmfFunctionInternal> newFunction)
+{
+ // Check to ensure that the name has valid characters
+ for (unsigned int i = 0; i < name.size(); ++i) {
+ // If the character is not found in the list of valid characters
+ if (mValidVariableChars.find(name[i]) == std::string::npos) {
+ // Then throw an error
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Function Name Contains Invalid Character(s)");
+ }
+ }
+ size_t origsize = arrayFunctions.size();
+ arrayFunctions[name] = newFunction;
+ // If no new functions were added
+ if (origsize == arrayFunctions.size()) {
+ // Toss a warning, it's nice to let people know that they're doing this
+ XdmfError::message(XdmfError::WARNING,
+ "Warning: Function Overwritten");
+ }
+ return arrayFunctions.size();
+}
+
+int
+XdmfFunction::addOperation(char newoperator,
+ shared_ptr<XdmfArray>(*operationref)(shared_ptr<XdmfArray>,
+ shared_ptr<XdmfArray>),
+ int priority)
+{
+ shared_ptr<XdmfOperationInternalImpl> newOperation =
+ XdmfOperationInternalImpl::New(operationref);
+ return XdmfFunction::addOperation(newoperator,
+ newOperation,
+ priority);
+}
+
+int
+XdmfFunction::addOperation(char newoperator,
+ shared_ptr<XdmfOperationInternal> newOperation,
+ int priority)
+{
+ if (newoperator == '(' || newoperator == ')') {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Parenthesis can not be redefined");
+ }
+ if (mValidVariableChars.find(newoperator) != std::string::npos
+ || mValidDigitChars.find(newoperator) != std::string::npos) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Operation Overlaps with Variables");
+ }
+ // Give warning if the operation already exists
+ size_t origsize = operations.size();
+ // Place reference in the associated location
+ operations[newoperator] = newOperation;
+ if (origsize == operations.size()) {
+ // It's nice to let people know they're doing this
+ // So they don't get surprised about changes in behavior
+ XdmfError::message(XdmfError::WARNING,
+ "Warning: Operation Overwritten");
+ // Overwrite the existing info for that operation
+ // Add the priority to the specified location in the priority array
+ mOperationPriority[newoperator] = priority;
+ }
+ else {
+ // Create new operation
+ // Add operation to the supported character string
+ mSupportedOperations.push_back(newoperator);
+ mOperationPriority[newoperator] = priority;
+ }
+ return operations.size();
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::addition(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ bool release1 = false;
+ bool release2 = false;
+ if (!val1->isInitialized()) {
+ val1->read();
+ release1 = true;
+ }
+ if (!val2->isInitialized()) {
+ val2->read();
+ release2 = true;
+ }
+ for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
+ if (val1->getSize() == val2->getSize()) {
+ returnArray->pushBack(val1->getValue<double>(i) + val2->getValue<double>(i));
+ }
+ else if (val1->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(0) + val2->getValue<double>(i));
+ }
+ else if (val2->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(i) + val2->getValue<double>(0));
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array Size Mismatch in Function addition");
+ }
+ }
+ if (release1) {
+ val1->release();
+ }
+ if (release2) {
+ val2->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::arcsin(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function arcsin");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(asin(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::arccos(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function arccos");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(acos(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::arctan(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function arctan");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(atan(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::average(std::vector<shared_ptr<XdmfArray> > values)
+{
+ double total = sum(values)->getValue<double>(0);;
+ int totalSize = 0;
+ bool release = false;
+ for (unsigned int i = 0; i < values.size(); ++i)
+ {
+ release = false;
+ if (!values[i]->isInitialized()) {
+ values[i]->read();
+ release = true;
+ }
+ totalSize += values[i]->getSize();
+ if (release) {
+ values[i]->release();
+ }
+ }
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ returnArray->insert(0, total/totalSize);
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::cos(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function cos");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(std::cos(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::chunk(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
+{
+ // Join chunk (add the new array to the end of the first one)
+ // Joins into new array and returns it
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Determining what type to class it as in order to not lose data
+ // and to still have the smallest data type of the two
+ shared_ptr<const XdmfArrayType> resultType =
+ XdmfArrayType::comparePrecision(val1->getArrayType(),
+ val2->getArrayType());
+ bool release1 = false;
+ bool release2 = false;
+ if (!val1->isInitialized()) {
+ val1->read();
+ release1 = true;
+ }
+ if (!val2->isInitialized()) {
+ val2->read();
+ release2 = true;
+ }
+ if (resultType == XdmfArrayType::Int8()) {
+ char sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Int16()) {
+ short sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Int32()) {
+ int sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Int64()) {
+ long sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt8()) {
+ unsigned char sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt16()) {
+ unsigned short sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt32()) {
+ unsigned int sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt64()) {
+ uint64_t sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Float32()) {
+ float sampleValue = 0.0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Float64()) {
+ double sampleValue = 0.0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::String()) {
+ std::string sampleValue = "";
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else {
+ // error type not supported
+ XdmfError::message(XdmfError::FATAL, "Invalid type during Chunk");
+ }
+ returnArray->insert(0, val1, 0, val1->getSize(), 1, 1);
+ returnArray->insert(val1->getSize(), val2, 0, val2->getSize(), 1, 1);
+ if (release1) {
+ val1->release();
+ }
+ if (release2) {
+ val2->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::exponent(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 2) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Two Arrays Needed for Function exponent");
+ }
+ bool release1 = false;
+ bool release2 = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release1 = true;
+ }
+ if (!values[1]->isInitialized()) {
+ values[1]->read();
+ release2 = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize() || i < values[1]->getSize(); ++i) {
+ if (values[0]->getSize() == values[1]->getSize()) {
+ returnArray->pushBack(std::pow(values[0]->getValue<double>(i), values[1]->getValue<double>(i)));
+ }
+ else if (values[0]->getSize() == 1) {
+ returnArray->pushBack(std::pow(values[0]->getValue<double>(0), values[1]->getValue<double>(i)));
+ }
+ else if (values[1]->getSize() == 1) {
+ returnArray->pushBack(std::pow(values[0]->getValue<double>(i), values[1]->getValue<double>(0)));
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array Size Mismatch in Function exponent");
+ }
+ }
+ if (release1) {
+ values[0]->release();
+ }
+ if (release2) {
+ values[1]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::division(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
+{
+ bool release1 = false;
+ bool release2 = false;
+ if (!val1->isInitialized()) {
+ val1->read();
+ release1 = true;
+ }
+ if (!val2->isInitialized()) {
+ val2->read();
+ release2 = true;
+ }
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
+ if (val1->getSize() == val2->getSize()) {
+ returnArray->pushBack(val1->getValue<double>(i) / val2->getValue<double>(i));
+ }
+ else if (val1->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(0) / val2->getValue<double>(i));
+ }
+ else if (val2->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(i) / val2->getValue<double>(0));
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array Size Mismatch in Function division");
+ }
+ }
+ if (release1) {
+ val1->release();
+ }
+ if (release2) {
+ val2->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::evaluateExpression(std::string expression,
+ std::map<std::string,
+ shared_ptr<XdmfArray> > variables)
+{
+ std::stack<shared_ptr<XdmfArray> > valueStack;
+ std::stack<char> operationStack;
+
+ // String is parsed left to right
+ // Elements of the same priority are evaluated right to left
+ for (unsigned int i = 0; i < expression.size(); ++i) {
+ bool hyphenIsDigit = false;
+ // hyphen is a special case since it can be used to annotate negative numbers
+ if (expression[i] == '-') {
+ if (i == 0) {
+ //would have to be a digit, otherwise it would be a unpaired operation
+ hyphenIsDigit = true;
+ }
+ else if (mValidDigitChars.find(expression[i+1]) != std::string::npos) {
+ // If value after is a valid digit,
+ // check value before
+ // If a digit, it's an operation
+ // If a variable, it's an operation
+ // If an operation, it's a digit character
+ if (mSupportedOperations.find(expression[i-1]) != std::string::npos) {
+ hyphenIsDigit = true;
+ }
+ else if (expression[i-1] <= ' ') {
+ // If whitespace is in front of the hyphen it is presumed to be a negative sign
+ // This is to handle passing negative values to functions properly
+ hyphenIsDigit = true;
+ }
+ }
+ }
+ // Found to be a digit
+ if (mValidDigitChars.find(expression[i]) != std::string::npos ||
+ (expression[i] == '-' && hyphenIsDigit)) {
+ // Progress until a non-digit is found
+ int valueStart = i;
+ if (i + 1 < expression.size()) {
+ while (mValidDigitChars.find(expression[i+1]) != std::string::npos) {
+ i++;
+ }
+ }
+ // Push back to the value stack
+ shared_ptr<XdmfArray> valueArray = XdmfArray::New();
+ // Use this to convert to double
+ valueArray->insert(0, atof(expression.substr(valueStart, i + 1 - valueStart).c_str()));
+ valueStack.push(valueArray);
+ }
+ else if (mValidVariableChars.find(expression[i]) != std::string::npos) {
+ // Found to be a variable
+ int valueStart = i;
+ // Progress until a nonvariable value is found
+ if (i+1 < expression.size()){
+ while (mValidVariableChars.find(expression[i+1]) != std::string::npos) {
+ i++;
+ }
+ }
+ // Convert to equivalent
+ if (variables.find(expression.substr(valueStart, i + 1 - valueStart))
+ == variables.end()) {
+ if (arrayFunctions.find(expression.substr(valueStart, i + 1 - valueStart))
+ == arrayFunctions.end()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Variable in evaluateExpression "
+ + expression.substr(valueStart, i + 1 - valueStart));
+ }
+ else {
+ std::string currentFunction =
+ expression.substr(valueStart, i + 1 - valueStart);
+ // Check if next character is an open parenthesis
+ if (i+1 >= expression.size()) {
+ if (expression[i+1] != '(') {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No values supplied to function "
+ + expression.substr(valueStart, i + 1 - valueStart));
+ }
+ }
+ // If it is grab the string between paranthesis
+
+ if (i + 2 >= expression.size()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Missing closing parethesis to function "
+ + expression.substr(valueStart, i + 1 - valueStart));
+ }
+ i = i + 2;
+ valueStart = i;
+ int numOpenParenthesis = 0;
+ while ((expression[i] != ')' || numOpenParenthesis) && i < expression.size()) {
+ if (expression[i] == '(') {
+ numOpenParenthesis++;
+ }
+ else if (expression[i] == ')') {
+ numOpenParenthesis--;
+ }
+ i++;
+ }
+ std::string functionParameters = expression.substr(valueStart, i - valueStart);
+ std::vector<shared_ptr<XdmfArray> > parameterVector;
+ // Split that string at commas
+ size_t parameterSplit = 0;
+ while (parameterSplit != std::string::npos) {
+ parameterSplit = 0;
+ parameterSplit = functionParameters.find_first_of(",", parameterSplit);
+ // Feed the substrings to the parse function
+ if (parameterSplit == std::string::npos) {
+ parameterVector.push_back(evaluateExpression(functionParameters, variables));
+ }
+ else {
+ parameterVector.push_back(
+ evaluateExpression(functionParameters.substr(0, parameterSplit),
+ variables));
+ functionParameters = functionParameters.substr(parameterSplit+1);
+ }
+ }
+ valueStack.push(evaluateFunction(parameterVector, currentFunction));
+ }
+ }
+ else {
+ // Push equivalent to value stack
+ valueStack.push(variables.find(expression.substr(valueStart, i + 1 - valueStart))->second);
+ }
+ }
+ else if (mSupportedOperations.find(expression[i]) != std::string::npos) {
+ // Found to be an operation
+ // Pop operations off the stack until one of a lower or equal importance is found
+ if (operationStack.size() > 0) {
+ if (expression[i] == ')') {
+ // To close a parenthesis pop off all operations until another parentheis is found
+ while (operationStack.size() > 0 && operationStack.top() != '(') {
+ // Must be at least two values for this loop to work properly
+ if (valueStack.size() < 2) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Not Enough Values in evaluateExpression");
+ }
+ else {
+ shared_ptr<XdmfArray> val2 = valueStack.top();
+ valueStack.pop();
+ shared_ptr<XdmfArray> val1 = valueStack.top();
+ valueStack.pop();
+ valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
+ operationStack.pop();
+ }
+ }
+ operationStack.pop();
+ }
+ else if (expression[i] == '(') {
+ // Just add it if it's a start parenthesis
+ // Nothing happens here in that case
+ // Addition happens after the if statement
+ }
+ else {
+ int operationLocation = getOperationPriority(expression[i]);
+ int topOperationLocation = getOperationPriority(operationStack.top());
+ // See order of operations to determine importance
+ while (operationStack.size() > 0 && operationLocation < topOperationLocation) {
+ // Must be at least two values for this loop to work properly
+ if (valueStack.size() < 2) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Not Enough Values in evaluateExpression");
+ }
+ else {
+ shared_ptr<XdmfArray> val2 = valueStack.top();
+ valueStack.pop();
+ shared_ptr<XdmfArray> val1 = valueStack.top();
+ valueStack.pop();
+ valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
+ operationStack.pop();
+ if (operationStack.size() == 0) {
+ break;
+ }
+ topOperationLocation = getOperationPriority(operationStack.top());
+ }
+ }
+ }
+ }
+ if (expression[i] != ')') {
+ // Add the operation to the operation stack
+ operationStack.push(expression[i]);
+ }
+ }
+ // If not a value or operation the character is ignored
+ }
+
+ // Empty what's left in the stacks before finishing
+ while (valueStack.size() > 1 && operationStack.size() > 0) {
+ if (valueStack.size() < 2) {
+ // Must be at least two values for this loop to work properly
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Not Enough Values in evaluateExpression");
+ }
+ else {
+ if(operationStack.top() == '(') {
+ XdmfError::message(XdmfError::WARNING,
+ "Warning: Unpaired Parenthesis");
+ }
+ else {
+ shared_ptr<XdmfArray> val2 = valueStack.top();
+ valueStack.pop();
+ shared_ptr<XdmfArray> val1 = valueStack.top();
+ valueStack.pop();
+ if (operationStack.size() == 0) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Not Enough Operators in evaluateExpression");
+ }
+ else {
+ valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
+ operationStack.pop();
+ }
+ }
+ }
+ }
+
+ // Throw error if there's extra operations
+ if (operationStack.size() > 0) {
+ XdmfError::message(XdmfError::WARNING,
+ "Warning: Left Over Operators in evaluateExpression");
+ }
+
+ if (valueStack.size() > 1) {
+ XdmfError::message(XdmfError::WARNING,
+ "Warning: Left Over Values in evaluateExpression");
+ }
+
+ // Ensure that an array is returned
+ // Will error out if this is not done.
+ if (valueStack.size() > 0) {
+ return valueStack.top();
+ }
+ else {
+ return XdmfArray::New();
+ }
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::evaluateOperation(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2,
+ char operation)
+{
+ if (operations.find(operation) != operations.end()) {
+ return operations[operation]->execute(val1, val2);
+ }
+ else {
+ return shared_ptr<XdmfArray>();
+ }
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::evaluateFunction(std::vector<shared_ptr<XdmfArray> > valueVector,
+ std::string functionName)
+{
+ if (arrayFunctions.find(functionName) != arrayFunctions.end()) {
+ return arrayFunctions[functionName]->execute(valueVector);
+ }
+ else {
+ return shared_ptr<XdmfArray>();
+ }
+}
+
+std::string
+XdmfFunction::getExpression() const
+{
+ return mExpression;
+}
+
+std::string
+XdmfFunction::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::map<std::string, std::string>
+XdmfFunction::getItemProperties() const
+{
+ std::map<std::string, std::string> functionProperties = XdmfArrayReference::getItemProperties();
+
+ functionProperties["Expression"] = mExpression;
+
+ std::stringstream variableStream;
+
+ for (std::map<std::string, shared_ptr<XdmfArray> >::const_iterator variableIter = mVariableList.begin();
+ variableIter != mVariableList.end();
+ ++variableIter) {
+ variableStream << "|" << variableIter->first;
+ }
+
+ functionProperties["VariableNames"] = variableStream.str();
+
+ return functionProperties;
+}
+
+int
+XdmfFunction::getOperationPriority(char operation)
+{
+ size_t operationLocation = mSupportedOperations.find(operation);
+ if (operationLocation != std::string::npos) {
+ return mOperationPriority[operation];
+ }
+ else {
+ return -1;
+ }
+}
+
+
+const std::string
+XdmfFunction::getSupportedOperations()
+{
+ return mSupportedOperations;
+}
+
+const std::vector<std::string>
+XdmfFunction::getSupportedFunctions()
+{
+ std::vector<std::string> returnVector;
+ for (std::map<std::string, shared_ptr<XdmfFunctionInternal> >::iterator functionWalker
+ = arrayFunctions.begin();
+ functionWalker != arrayFunctions.end();
+ ++functionWalker) {
+ returnVector.push_back(functionWalker->first);
+ }
+ return returnVector;
+}
+
+const std::string
+XdmfFunction::getValidDigitChars()
+{
+ return mValidDigitChars;
+}
+
+const std::string
+XdmfFunction::getValidVariableChars()
+{
+ return mValidVariableChars;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::getVariable(std::string key)
+{
+ if (mVariableList.count(key) > 0) {
+ return mVariableList[key];
+ }
+ else {
+ return shared_ptr<XdmfArray>();
+ }
+}
+
+std::vector<std::string>
+XdmfFunction::getVariableList()
+{
+ std::vector<std::string> keyAccumulator;
+ for (std::map<std::string, shared_ptr<XdmfArray> >::iterator it = mVariableList.begin();
+ it != mVariableList.end();
+ ++it) {
+ keyAccumulator.push_back(it->first);
+ }
+ return keyAccumulator;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::interlace(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
+{
+ // Join interlace (evenly space the second array within the first one)
+ // Builds a new array
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Resize to the combined size of both arrays
+ // Determining what type to class it as in order to not lose data
+ // and to still have the smallest data type of the two
+ shared_ptr<const XdmfArrayType> resultType =
+ XdmfArrayType::comparePrecision(val1->getArrayType(), val2->getArrayType());
+ bool release1 = false;
+ bool release2 = false;
+ if (!val1->isInitialized()) {
+ val1->read();
+ release1 = true;
+ }
+ if (!val2->isInitialized()) {
+ val2->read();
+ release2 = true;
+ }
+ if (resultType == XdmfArrayType::Int8()) {
+ char sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Int16()) {
+ short sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Int32()) {
+ int sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Int64()) {
+ long sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt8()) {
+ unsigned char sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt16()) {
+ unsigned short sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt32()) {
+ unsigned int sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::UInt64()) {
+ uint64_t sampleValue = 0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Float32()) {
+ float sampleValue = 0.0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::Float64()) {
+ double sampleValue = 0.0;
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else if (resultType == XdmfArrayType::String()) {
+ std::string sampleValue = "";
+ returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
+ }
+ else {
+ // error type not supported
+ XdmfError::message(XdmfError::FATAL, "Invalid type during Interlace");
+ }
+
+ // Determine ratio of array sizes
+ int arrayRatio1 = (int)floor(static_cast<double>(val1->getSize())/val2->getSize());
+ int arrayRatio2 = (int)floor(static_cast<double>(val2->getSize())/val1->getSize());
+ if (arrayRatio1 < 1) {
+ arrayRatio1 = 1;
+ }
+ if (arrayRatio2 < 1) {
+ arrayRatio2 = 1;
+ }
+ // Stride is equal to the ratios rounded up and added together
+ int stride = arrayRatio1+arrayRatio2;
+ int arrayExcess1 = 0;
+ int arrayExcess2 = 0;
+ for (int i = 0; i < stride; ++i) {
+ // Add the values of each array
+ // using strides to interlace and starting index to offset
+ // first array gets the first value of the new array
+ if (i<arrayRatio1) {
+ int amountWritten = val1->getSize()/arrayRatio1;
+ if (((amountWritten * arrayRatio1) + i) < (int)val1->getSize()) {
+ amountWritten++;
+ }
+ if (amountWritten > floor(static_cast<double>(val2->getSize())/arrayRatio2)) {
+ arrayExcess1 += amountWritten - (int)floor(static_cast<double>(val2->getSize())/arrayRatio2);
+ amountWritten = (int)floor(static_cast<double>(val2->getSize())/arrayRatio2);
+ }
+ returnArray->insert(i, val1, i, amountWritten, stride, arrayRatio1);
+ }
+ else {
+ // Second array takes the rest
+ int amountWritten = val2->getSize()/arrayRatio2;
+ if (((amountWritten * arrayRatio2) + i) < (int)val2->getSize()) {
+ amountWritten++;
+ }
+ if (amountWritten > floor(static_cast<double>(val1->getSize())/arrayRatio1)) {
+ arrayExcess2 += amountWritten - (int)floor(static_cast<double>(val1->getSize())/arrayRatio1);
+ amountWritten = (int)floor(static_cast<double>(val1->getSize())/arrayRatio1);
+ }
+ returnArray->insert(i, val2, i-arrayRatio1, amountWritten, stride, arrayRatio2);
+ }
+ }
+ if (arrayExcess1 > 0) {
+ returnArray->insert(val1->getSize()+val2->getSize()-arrayExcess1,
+ val1,
+ val1->getSize()-arrayExcess1,
+ arrayExcess1,
+ 1,
+ 1);
+ }
+ else if (arrayExcess2 > 0) {
+ returnArray->insert(val1->getSize()+val2->getSize()-arrayExcess2,
+ val2,
+ val2->getSize()-arrayExcess2,
+ arrayExcess2,
+ 1,
+ 1);
+ }
+ // After all inserts are done, add the excess values to the end of the array
+ if (release1) {
+ val1->release();
+ }
+ if (release2) {
+ val2->release();
+ }
+ return returnArray;
+}
+
+void
+XdmfFunction::insertVariable(std::string key, shared_ptr<XdmfArray> value)
+{
+ mVariableList[key] = value;
+ this->setIsChanged(true);
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::join(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ bool release = false;
+ for (unsigned int i = 0; i < values.size(); ++i) {
+ release = false;
+ if (!values[i]->isInitialized()) {
+ values[i]->read();
+ release = true;
+ }
+ returnArray->insert(returnArray->getSize(),
+ values[i],
+ 0,
+ values[i]->getSize(),
+ 1,
+ 1);
+ if (release) {
+ values[i]->release();
+ }
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::log(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function log");
+ }
+ bool release1 = false;
+ bool release2 = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release1 = true;
+ }
+ if (values.size() > 1) {
+ if (!values[1]->isInitialized()) {
+ values[1]->read();
+ release2 = true;
+ }
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ if (values.size() > 1) {
+ if (values[0]->getSize() == values[1]->getSize()) {
+ returnArray->pushBack(std::log(values[0]->getValue<double>(i))/std::log(values[1]->getValue<double>(i)));
+ }
+ else if (values[1]->getSize() == 1) {
+ returnArray->pushBack(std::log(values[0]->getValue<double>(i))/std::log(values[1]->getValue<double>(0)));
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array Size Missmatch in Function Log");
+ }
+ }
+ else {
+ returnArray->pushBack(std::log(values[0]->getValue<double>(i)));
+ }
+ }
+ if (release1) {
+ values[0]->release();
+ }
+ if (release2) {
+ values[1]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::multiplication(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ bool release1 = false;
+ bool release2 = false;
+ if (!val1->isInitialized()) {
+ val1->read();
+ release1 = true;
+ }
+ if (!val2->isInitialized()) {
+ val2->read();
+ release2 = true;
+ }
+ for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
+ if (val1->getSize() == val2->getSize()) {
+ returnArray->pushBack(val1->getValue<double>(i) * val2->getValue<double>(i));
+ }
+ else if (val1->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(0) * val2->getValue<double>(i));
+ }
+ else if (val2->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(i) * val2->getValue<double>(0));
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array Size Mismatch in Function multiplication");
+ }
+ }
+ if (release1) {
+ val1->release();
+ }
+ if (release2) {
+ val2->release();
+ }
+ return returnArray;
+}
+
+
+shared_ptr<XdmfArray>
+XdmfFunction::read() const
+{
+ return evaluateExpression(mExpression, mVariableList);
+}
+
+void
+XdmfFunction::removeVariable(std::string key)
+{
+ std::map<std::string, shared_ptr<XdmfArray> >::iterator removeWalker =
+ mVariableList.find(key);
+ if (removeWalker != mVariableList.end()) {
+ mVariableList.erase(removeWalker);
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfFunction::setExpression(std::string newExpression)
+{
+ mExpression = newExpression;
+ this->setIsChanged(true);
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::sin(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function sin");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(std::sin(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::sqrt(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function sqrt");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(std::sqrt(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::subtraction(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ bool release1 = false;
+ bool release2 = false;
+ if (!val1->isInitialized()) {
+ val1->read();
+ release1 = true;
+ }
+ if (!val2->isInitialized()) {
+ val2->read();
+ release2 = true;
+ }
+ for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
+ if (val1->getSize() == val2->getSize()) {
+ returnArray->pushBack(val1->getValue<double>(i) - val2->getValue<double>(i));
+ }
+ else if (val1->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(0) - val2->getValue<double>(i));
+ }
+ else if (val2->getSize() == 1) {
+ returnArray->pushBack(val1->getValue<double>(i) - val2->getValue<double>(0));
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array Size Mismatch in Function subtraction");
+ }
+ }
+ if (release1) {
+ val1->release();
+ }
+ if (release2) {
+ val2->release();
+ }
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::sum(std::vector<shared_ptr<XdmfArray> > values)
+{
+ double total = 0.0;
+ bool release = false;
+ for (unsigned int i = 0; i < values.size(); ++i) {
+ release = false;
+ if (!values[i]->isInitialized()) {
+ values[i]->read();
+ release = true;
+ }
+ for (unsigned int j = 0; j < values[i]->getSize(); ++j) {
+ total += values[i]->getValue<double>(j);
+ }
+ if (release) {
+ values[i]->release();
+ }
+ }
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ returnArray->insert(0, total);
+ return returnArray;
+}
+
+shared_ptr<XdmfArray>
+XdmfFunction::tan(std::vector<shared_ptr<XdmfArray> > values)
+{
+ shared_ptr<XdmfArray> returnArray = XdmfArray::New();
+ // Only working with the first array provided
+ if (values.size() < 1) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: No Array Passed to Function tan");
+ }
+ bool release = false;
+ if (!values[0]->isInitialized()) {
+ values[0]->read();
+ release = true;
+ }
+ for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
+ returnArray->pushBack(std::tan(values[0]->getValue<double>(i)));
+ }
+ if (release) {
+ values[0]->release();
+ }
+ return returnArray;
+}
+
+void
+XdmfFunction::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+
+ bool originalXPath;
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ originalXPath = writer->getWriteXPaths();
+ writer->setWriteXPaths(false);
+ }
+
+ shared_ptr<XdmfArray> spacerarray = XdmfArray::New();
+ spacerarray->pushBack((int)0);
+ spacerarray->accept(visitor);
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ writer->setWriteXPaths(originalXPath);
+ }
+
+ for (std::map<std::string, shared_ptr<XdmfArray> >::iterator it = mVariableList.begin();
+ it != mVariableList.end();
+ ++it) {
+ it->second->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+class XdmfCFunctionInternalImpl : public XdmfFunction::XdmfFunctionInternal {
+ public:
+ static shared_ptr<XdmfCFunctionInternalImpl>
+ New(XDMFARRAY * (*newInternal)(XDMFARRAY **, unsigned int))
+ {
+ shared_ptr<XdmfCFunctionInternalImpl> p (new XdmfCFunctionInternalImpl(newInternal));
+ return p;
+ }
+
+ ~XdmfCFunctionInternalImpl()
+ {
+ }
+
+ virtual shared_ptr<XdmfArray> execute(std::vector<shared_ptr<XdmfArray> > valueVector)
+ {
+ XDMFARRAY ** valueArray = new XDMFARRAY *[valueVector.size()]();
+ for (unsigned int i = 0; i < valueVector.size(); ++i) {
+ valueArray[i] = (XDMFARRAY *)((void *)(valueVector[i].get()));
+ }
+ return shared_ptr<XdmfArray>((XdmfArray *)((*mInternalFunction)(valueArray, valueVector.size())));
+ }
+ private:
+ XdmfCFunctionInternalImpl(XDMFARRAY * (*newInternal)(XDMFARRAY **, unsigned int))
+ {
+ mInternalFunction = newInternal;
+ }
+
+ XDMFARRAY * (*mInternalFunction)(XDMFARRAY **, unsigned int);
+};
+
+class XdmfCOperationInternalImpl : public XdmfFunction::XdmfOperationInternal {
+ public:
+ static shared_ptr<XdmfCOperationInternalImpl>
+ New(XDMFARRAY * (*newInternal)(XDMFARRAY *, XDMFARRAY *))
+ {
+ shared_ptr<XdmfCOperationInternalImpl> p (new XdmfCOperationInternalImpl(newInternal));
+ return p;
+ }
+
+ ~XdmfCOperationInternalImpl()
+ {
+ }
+
+ virtual shared_ptr<XdmfArray> execute(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2)
+ {
+ return shared_ptr<XdmfArray>((XdmfArray *)((*mInternalOperation)((XDMFARRAY *)((void *)(val1.get())), (XDMFARRAY *)((void *)(val2.get())))));
+ }
+ private:
+ XdmfCOperationInternalImpl(XDMFARRAY * (*newInternal)(XDMFARRAY *, XDMFARRAY *))
+ {
+ mInternalOperation = newInternal;
+ }
+
+ XDMFARRAY * (*mInternalOperation)(XDMFARRAY *, XDMFARRAY *);
+};
+
+XDMFFUNCTION * XdmfFunctionNew()
+{
+ try
+ {
+ shared_ptr<XdmfFunction> generatedFunction = XdmfFunction::New();
+ return (XDMFFUNCTION *)((void *)(new XdmfFunction(*generatedFunction.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfFunction> generatedFunction = XdmfFunction::New();
+ return (XDMFFUNCTION *)((void *)(new XdmfFunction(*generatedFunction.get())));
+ }
+}
+
+XDMFFUNCTION * XdmfFunctionNewInit(char * newExpression, char ** keys, XDMFARRAY ** values, int numVariables)
+{
+ try
+ {
+ std::map<std::string, shared_ptr<XdmfArray> > variableMap;
+ for (int i = 0; i < numVariables; ++i) {
+ variableMap[keys[i]] = shared_ptr<XdmfArray>((XdmfArray *)(values[i]), XdmfNullDeleter());
+ }
+ shared_ptr<XdmfFunction> generatedFunction = XdmfFunction::New(std::string(newExpression), variableMap);
+ return (XDMFFUNCTION *)((void *)(new XdmfFunction(*generatedFunction.get())));
+ }
+ catch (...)
+ {
+ std::map<std::string, shared_ptr<XdmfArray> > variableMap;
+ for (int i = 0; i < numVariables; ++i) {
+ variableMap[keys[i]] = shared_ptr<XdmfArray>((XdmfArray *)(values[i]), XdmfNullDeleter());
+ }
+ shared_ptr<XdmfFunction> generatedFunction = XdmfFunction::New(std::string(newExpression), variableMap);
+ return (XDMFFUNCTION *)((void *)(new XdmfFunction(*generatedFunction.get())));
+ }
+}
+
+int XdmfFunctionAddFunction(char * name, XDMFARRAY *(*functionref)(XDMFARRAY **, unsigned int), int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ shared_ptr<XdmfCFunctionInternalImpl> newFunction =
+ XdmfCFunctionInternalImpl::New(functionref);
+ return XdmfFunction::addFunction(name, newFunction);
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfCFunctionInternalImpl> newFunction =
+ XdmfCFunctionInternalImpl::New(functionref);
+ return XdmfFunction::addFunction(name, newFunction);
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+int XdmfFunctionAddOperation(char newoperator, XDMFARRAY *(*operationref)(XDMFARRAY *, XDMFARRAY *), int priority, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ shared_ptr<XdmfCOperationInternalImpl> newOperation =
+ XdmfCOperationInternalImpl::New(operationref);
+ return XdmfFunction::addOperation(newoperator,
+ newOperation,
+ priority);
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfCOperationInternalImpl> newOperation =
+ XdmfCOperationInternalImpl::New(operationref);
+ return XdmfFunction::addOperation(newoperator,
+ newOperation,
+ priority);
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+XDMFARRAY * XdmfFunctionAverage(XDMFARRAY ** values, int numValues)
+{
+ try
+ {
+ std::vector<shared_ptr<XdmfArray> > valueVector;
+ for (int i = 0; i < numValues; ++i) {
+ valueVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)values[i], XdmfNullDeleter()));
+ }
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::average(valueVector).get()))));
+ }
+ catch (...)
+ {
+ std::vector<shared_ptr<XdmfArray> > valueVector;
+ for (int i = 0; i < numValues; ++i) {
+ valueVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)values[i], XdmfNullDeleter()));
+ }
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::average(valueVector).get()))));
+ }
+}
+
+XDMFARRAY * XdmfFunctionChunk(XDMFARRAY * val1, XDMFARRAY * val2, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::chunk(shared_ptr<XdmfArray>((XdmfArray *)val1, XdmfNullDeleter()), shared_ptr<XdmfArray>((XdmfArray *)val2, XdmfNullDeleter())).get()))));
+ }
+ catch (...)
+ {
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::chunk(shared_ptr<XdmfArray>((XdmfArray *)val1, XdmfNullDeleter()), shared_ptr<XdmfArray>((XdmfArray *)val2, XdmfNullDeleter())).get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfFunctionEvaluateExpression(char * expression, char ** keys, XDMFARRAY ** values, int numVariables, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::map<std::string, shared_ptr<XdmfArray> > variableMap;
+ for (int i = 0; i < numVariables; ++i) {
+ variableMap[keys[i]] = shared_ptr<XdmfArray>((XdmfArray *)(values[i]), XdmfNullDeleter());
+ }
+ shared_ptr<XdmfArray> generatedArray = XdmfFunction::evaluateExpression(std::string(expression), variableMap);
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(generatedArray.get()))));
+ }
+ catch (...)
+ {
+ std::map<std::string, shared_ptr<XdmfArray> > variableMap;
+ for (int i = 0; i < numVariables; ++i) {
+ variableMap[keys[i]] = shared_ptr<XdmfArray>((XdmfArray *)(values[i]), XdmfNullDeleter());
+ }
+ shared_ptr<XdmfArray> generatedArray = XdmfFunction::evaluateExpression(std::string(expression), variableMap);
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(generatedArray.get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfFunctionEvaluateOperation(XDMFARRAY * val1, XDMFARRAY * val2, char operation, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ shared_ptr<XdmfArray> generatedArray = XdmfFunction::evaluateOperation(shared_ptr<XdmfArray>((XdmfArray *)(val1), XdmfNullDeleter()), shared_ptr<XdmfArray>((XdmfArray *)(val2), XdmfNullDeleter()), operation);
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(generatedArray.get()))));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfArray> generatedArray = XdmfFunction::evaluateOperation(shared_ptr<XdmfArray>((XdmfArray *)(val1), XdmfNullDeleter()), shared_ptr<XdmfArray>((XdmfArray *)(val2), XdmfNullDeleter()), operation);
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(generatedArray.get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfFunctionEvaluateFunction(XDMFARRAY ** valueVector, int numValues, char * functionName, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<shared_ptr<XdmfArray> > evaluatedVector;
+ for (int i = 0; i < numValues; ++i) {
+ evaluatedVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)valueVector[i], XdmfNullDeleter()));
+ }
+ shared_ptr<XdmfArray> generatedArray = XdmfFunction::evaluateFunction(evaluatedVector, std::string(functionName));
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(generatedArray.get()))));
+ }
+ catch (...)
+ {
+ std::vector<shared_ptr<XdmfArray> > evaluatedVector;
+ for (int i = 0; i < numValues; ++i) {
+ evaluatedVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)valueVector[i], XdmfNullDeleter()));
+ }
+ shared_ptr<XdmfArray> generatedArray = XdmfFunction::evaluateFunction(evaluatedVector, std::string(functionName));
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(generatedArray.get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+char * XdmfFunctionGetExpression(XDMFFUNCTION * function)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfFunction *)(function))->getExpression().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfFunction *)(function))->getExpression().c_str());
+ return returnPointer;
+ }
+}
+
+unsigned int XdmfFunctionGetNumberVariables(XDMFFUNCTION * function)
+{
+ return ((XdmfFunction *)(function))->getVariableList().size();
+}
+
+int XdmfFunctionGetOperationPriority(char operation)
+{
+ return XdmfFunction::getOperationPriority(operation);
+}
+
+char * XdmfFunctionGetSupportedOperations()
+{
+ try
+ {
+ return strdup(XdmfFunction::getSupportedOperations().c_str());
+ }
+ catch (...)
+ {
+ return strdup(XdmfFunction::getSupportedOperations().c_str());
+ }
+}
+
+char ** XdmfFunctionGetSupportedFunctions()
+{
+ try
+ {
+ std::vector<std::string> supportedFunctions = XdmfFunction::getSupportedFunctions();
+ char ** returnPointer = new char *[supportedFunctions.size()]();
+ for (unsigned int i = 0; i < supportedFunctions.size(); ++i) {
+ returnPointer[i] = strdup(supportedFunctions[i].c_str());
+ }
+ return returnPointer;
+ }
+ catch (...)
+ {
+ std::vector<std::string> supportedFunctions = XdmfFunction::getSupportedFunctions();
+ char ** returnPointer = new char *[supportedFunctions.size()]();
+ for (unsigned int i = 0; i < supportedFunctions.size(); ++i) {
+ returnPointer[i] = strdup(supportedFunctions[i].c_str());
+ }
+ return returnPointer;
+ }
+}
+
+unsigned int XdmfFunctionGetNumberSupportedFunctions()
+{
+ return XdmfFunction::getSupportedFunctions().size();
+}
+
+char * XdmfFunctionGetValidDigitChars()
+{
+ try
+ {
+ return strdup(XdmfFunction::getValidDigitChars().c_str());
+ }
+ catch (...)
+ {
+ return strdup(XdmfFunction::getValidDigitChars().c_str());
+ }
+}
+
+char * XdmfFunctionGetValidVariableChars()
+{
+ try
+ {
+ return strdup(XdmfFunction::getValidVariableChars().c_str());
+ }
+ catch (...)
+ {
+ return strdup(XdmfFunction::getValidVariableChars().c_str());
+ }
+}
+
+XDMFARRAY * XdmfFunctionGetVariable(XDMFFUNCTION * function, char * key)
+{
+ try
+ {
+ shared_ptr<XdmfArray> returnArray = ((XdmfFunction *)function)->getVariable(std::string(key));
+ return (XDMFARRAY *)((void *)(new XdmfArray(*returnArray.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfArray> returnArray = ((XdmfFunction *)function)->getVariable(std::string(key));
+ return (XDMFARRAY *)((void *)(new XdmfArray(*returnArray.get())));
+ }
+}
+
+char ** XdmfFunctionGetVariableList(XDMFFUNCTION * function)
+{
+ try
+ {
+ std::vector<std::string> variablelist = ((XdmfFunction *)(function))->getVariableList();
+ char ** returnpointer = new char *[variablelist.size()]();
+ for (unsigned int i = 0; i < variablelist.size(); ++i) {
+ returnpointer[i] = strdup(variablelist[i].c_str());
+ }
+ return returnpointer;
+ }
+ catch (...)
+ {
+ std::vector<std::string> variablelist = ((XdmfFunction *)(function))->getVariableList();
+ char ** returnpointer = new char *[variablelist.size()]();
+ for (unsigned int i = 0; i < variablelist.size(); ++i) {
+ returnpointer[i] = strdup(variablelist[i].c_str());
+ }
+ return returnpointer;
+ }
+}
+
+XDMFARRAY * XdmfFunctionInterlace(XDMFARRAY * val1, XDMFARRAY * val2, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::interlace(shared_ptr<XdmfArray>((XdmfArray *)val1, XdmfNullDeleter()), shared_ptr<XdmfArray>((XdmfArray *)val2, XdmfNullDeleter())).get()))));
+ }
+ catch (...)
+ {
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::interlace(shared_ptr<XdmfArray>((XdmfArray *)val1, XdmfNullDeleter()), shared_ptr<XdmfArray>((XdmfArray *)val2, XdmfNullDeleter())).get()))));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void XdmfFunctionInsertVariable(XDMFFUNCTION * function, char * key, XDMFARRAY * value, int passControl)
+{
+ shared_ptr<XdmfArray> insertedValue;
+ if (passControl == 0) {
+ insertedValue = shared_ptr<XdmfArray>((XdmfArray *)value, XdmfNullDeleter());
+ }
+ else {
+ insertedValue = shared_ptr<XdmfArray>((XdmfArray *)value);
+ }
+ ((XdmfFunction *)function)->insertVariable(std::string(key), insertedValue);
+}
+
+void XdmfFunctionRemoveVariable(XDMFFUNCTION * function, char * key)
+{
+ ((XdmfFunction *)(function))->removeVariable(std::string(key));
+}
+
+void XdmfFunctionSetExpression(XDMFFUNCTION * function, char * newExpression, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfFunction *)(function))->setExpression(std::string(newExpression));
+ XDMF_ERROR_WRAP_END(status)
+}
+
+XDMFARRAY * XdmfFunctionSum(XDMFARRAY ** values, int numValues)
+{
+ try
+ {
+ std::vector<shared_ptr<XdmfArray> > valueVector;
+ for (int i = 0; i < numValues; ++i) {
+ valueVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)values[i], XdmfNullDeleter()));
+ }
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::sum(valueVector).get()))));
+ }
+ catch (...)
+ {
+ std::vector<shared_ptr<XdmfArray> > valueVector;
+ for (int i = 0; i < numValues; ++i) {
+ valueVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)values[i], XdmfNullDeleter()));
+ }
+ return (XDMFARRAY *)((void *)(new XdmfArray(*(XdmfFunction::sum(valueVector).get()))));
+ }
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfFunction, XDMFFUNCTION)
+XDMF_ARRAYREFERENCE_C_CHILD_WRAPPER(XdmfFunction, XDMFFUNCTION)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfFunction.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFFUNCTION_HPP_
+#define XDMFFUNCTION_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfArrayReference.hpp"
+
+#ifdef __cplusplus
+
+class XdmfArray;
+
+/**
+ * @brief Manipulates arrays based on expressions.
+ *
+ * The function class provides a way to manipulate XdmfArrays via predefined functions.
+ */
+class XDMFCORE_EXPORT XdmfFunction : public XdmfArrayReference {
+
+public:
+
+
+ /**
+ * Function wrapper to allow for more flexibility when wrapping
+ * functions to be used in the dynamic library.
+ *
+ * Not required to use the dynamic library because there are
+ * methods that take function pointers.
+ */
+ class XdmfFunctionInternal {
+ public:
+ virtual ~XdmfFunctionInternal()
+ {
+ }
+
+ virtual shared_ptr<XdmfArray>
+ execute(std::vector<shared_ptr<XdmfArray> > valueVector) = 0;
+ };
+
+ /**
+ * Binary Operator wrapper to allow for more flexibility when wrapping
+ * operations to be used in the dynamic library.
+ *
+ * Not required to use the dynamic library because there are
+ * methods that take function pointers.
+ */
+ class XdmfOperationInternal {
+ public:
+ virtual ~XdmfOperationInternal()
+ {
+ }
+
+ virtual shared_ptr<XdmfArray>
+ execute(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2) = 0;
+ };
+
+ /**
+ * Create a new XdmfFunction
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfFunction.
+ */
+ static shared_ptr<XdmfFunction> New();
+
+ /**
+ * Create a new XdmfFunction
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ *
+ * @param newExpression The expression that the function will evaluate
+ * @param newVariables The arrays that the function will use
+ * to evalute the expression
+ * @return Constructed XdmfFunction.
+ */
+ static shared_ptr<XdmfFunction>
+ New(std::string newExpression,
+ std::map<std::string,
+ shared_ptr<XdmfArray> > newVariables);
+
+ virtual ~XdmfFunction();
+
+ LOKI_DEFINE_VISITABLE(XdmfFunction, XdmfItem)
+
+ static const std::string ItemTag;
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the absolute value equivalent of that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#abs
+ * @until //#abs
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//abs
+ * @until #//abs
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the absolute value
+ * equivalent of the first array
+ */
+ static shared_ptr<XdmfArray> abs(std::vector<shared_ptr<XdmfArray> > values);
+
+ /*
+ * Adds a specified function to the list of functions used while
+ * evaluating strings
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declarefunction
+ * @until //#declarefunction
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#addFunction
+ * @until //#addFunction
+ * @skipline //#programend
+ * @until //#programend
+ * @skipline //#definefunction
+ * @until //#definefunction
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//definefunction
+ * @until #//definefunction
+ * @skipline #//programstart
+ * @until #//programstart
+ * @skipline #//addFunction
+ * @until #//addFunction
+ *
+ * @param name A string to be associated with the provided
+ * function during string evaluation
+ * @param functionref A pointer to the function to be associated
+ * with the given string
+ * @return The total number of functions currently usable
+ */
+ static int
+ addFunction(std::string name,
+ shared_ptr<XdmfArray>(*functionref)(std::vector<shared_ptr<XdmfArray> >));
+
+ /**
+ * Adds a specified function to the list of functions used while
+ * evaluating strings.
+ * This version allows for custom wrapping.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declarefunctionclass
+ * @until //#declarefunctionclass
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#addFunctionclass
+ * @until //#addFunctionclass
+ * @skipline //#programend
+ * @until //#programend
+ *
+ * Python: This version of addFunction is not supported in Python
+ *
+ * @param name A string to be associated with the provided
+ * function during string evaluation
+ * @param newFunction A shared pointer to the function to be
+ * associated with the given string
+ * @return The total number of functions currently usable
+ */
+ static int
+ addFunction(std::string name,
+ shared_ptr<XdmfFunctionInternal> newFunction);
+
+ /**
+ * Adds an operation to the list of viable binary operators.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declareoperation
+ * @until //#declareoperation
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#addOperation
+ * @until //#addOperation
+ * @skipline //#programend
+ * @until //#programend
+ * @skipline //#defineoperation
+ * @until //#defineoperation
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//defineoperation
+ * @until #//defineoperation
+ * @skipline #//programstart
+ * @until #//programstart
+ * @skipline #//addOperation
+ * @until #//addOperation
+ *
+ * @param newoperator The character to be associated with the provided
+ * binary operation
+ * @param functionref A pointer to the function to be associated with
+ * the provided operator
+ * @param priority Used to determine order of operations,
+ * the higher the value the earlier it is evaluated
+ * @return The number of viable operations
+ */
+ static int
+ addOperation(char newoperator,
+ shared_ptr<XdmfArray>(*functionref)(shared_ptr<XdmfArray>,
+ shared_ptr<XdmfArray>),
+ int priority);
+
+ /**
+ * Adds an operation to the list of viable binary operators.
+ * This version allows for custom wrapping.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declareoperationclass
+ * @until //#declareoperationclass
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#addOperationclass
+ * @until //#addOperationclass
+ * @skipline //#programend
+ * @until //#programend
+ *
+ * Python: This version of addOperation is not supported in Python
+ *
+ * @param newoperator The character to be associated with the provided
+ * binary operation
+ * @param newOperation A pointer to the function to be associated
+ * with the provided operator
+ * @param priority Used to determine order of operations,
+ * the higher the value the earlier it is evaluated
+ * @return The number of viable operations
+ */
+ static int
+ addOperation(char newoperator,
+ shared_ptr<XdmfOperationInternal> newOperation,
+ int priority);
+
+ /**
+ * Takes the arrays provided adds them together, returning the result.
+ *
+ * If the first array has one value an array is generated adding
+ * it to each value of the second array.
+ *
+ * If the second array has one value. That value is added to
+ * all values in the first array.
+ *
+ * If both arrays have the same number of values, the
+ * value of the first array is added to the value of the second array
+ * with the same index.
+ *
+ * An error is thrown if the array sizes are both large than 1
+ * and do not match.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#addition
+ * @until //#addition
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//addition
+ * @until #//addition
+ *
+ * @param val1 The first Array to be used
+ * @param val2 The second Array to be used
+ * @return An XdmfArray containing the sums
+ * of the values of the arrays
+ */
+ static shared_ptr<XdmfArray> addition(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the arcsin of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#arcsin
+ * @until //#arcsin
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//arcsin
+ * @until #//arcsin
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the arcsin of the
+ * values of the first array
+ */
+ static shared_ptr<XdmfArray> arcsin(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the arccos of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#arccos
+ * @until //#arccos
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//arccos
+ * @until #//arccos
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the arccos of the
+ * values of the first array
+ */
+ static shared_ptr<XdmfArray> arccos(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the arctan of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#arctan
+ * @until //#arctan
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//arctan
+ * @until #//arctan
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the arctan of the
+ * values of the first array
+ */
+ static shared_ptr<XdmfArray> arctan(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Averages the values contained in all the provided arrays.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#average
+ * @until //#average
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//average
+ * @until #//average
+ *
+ * @param values A vector containing the arrays to be used
+ * @return An XdmfArray containing one value which is the average
+ * of all values contained within the provided arrays
+ */
+ static shared_ptr<XdmfArray>
+ average(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Joins the two provided arrays together end to end.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#chunk
+ * @until //#chunk
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//chunk
+ * @until #//chunk
+ *
+ * @param val1 The first array being evaluated
+ * @param val2 The second array being evaluated
+ * @return The arrays joined end to end
+ */
+ static shared_ptr<XdmfArray>
+ chunk(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the cos of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#cos
+ * @until //#cos
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//cos
+ * @until #//cos
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the cos of the
+ * values of the first array
+ */
+ static shared_ptr<XdmfArray> cos(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the arrays provided and divides the first one by the second,
+ * returning the result.
+ *
+ * If the first array has one value an array is generated
+ * by dividing it by each value of the second array.
+ *
+ * If the second array has one value. Each value in the
+ * first array is divided by that value.
+ *
+ * If both arrays have the same number of values, each value of
+ * the first array is divided by the value of the second array
+ * with the same index.
+ *
+ * An error is thrown if the array sizes are both large than 1
+ * and do not match.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#division
+ * @until //#division
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//division
+ * @until #//division
+ *
+ * @param val1 The array to be divided
+ * @param val2 The array to be divided by
+ * @return An XdmfArray containing the results
+ * of the division of the arrays
+ */
+ static shared_ptr<XdmfArray> division(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the values in that array taken to a power relative to the second array.
+ *
+ * If the first array has one value an array is generated by raising that
+ * value to the power of each of the values in the second array
+ *
+ * If the second array has one value. That power is applied to each
+ * value of the first array
+ *
+ * If both arrays have the same number of values, each value of the
+ * first array is raised to the power of the value of the
+ * corresponding index of the second array.
+ *
+ * An error is thrown if the array sizes are both large than 1
+ * and do not match.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#exp
+ * @until //#exp
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//exp
+ * @until #//exp
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the powers
+ * of the values of the first array
+ */
+ static shared_ptr<XdmfArray> exponent(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Evaluates an expression based on the list of variables provided.
+ * A list of valid operations is retrievable from the getSupportedOperations
+ * static method.
+ * None of the XdmfArrays provided are modified during the evaluation process.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declarefunction
+ * @until //#declarefunction
+ * @skipline //#declareoperation
+ * @until //#declareoperation
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#addOperation
+ * @until //#addOperation
+ * @skipline //#addFunction
+ * @until //#addFunction
+ * @skipline //#evaluateExpression
+ * @until //#evaluateExpression
+ * @skipline //#programend
+ * @until //#programend
+ * @skipline //#definefunction
+ * @until //#definefunction
+ * @skipline //#defineoperation
+ * @until //#defineoperation
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//definefunction
+ * @until #//definefunction
+ * @skipline #//defineoperation
+ * @until #//defineoperation
+ * @skipline #//programstart
+ * @until #//programstart
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//addOperation
+ * @until #//addOperation
+ * @skipline #//addFunction
+ * @until #//addFunction
+ * @skipline #//evaluateExpression
+ * @until #//evaluateExpression
+ *
+ * @param expression A string containing the expresion to be evaluated
+ * @param variables A map of strings to their XdmfArray equivalent
+ * @return A shared pointer to the XdmfArray resulting
+ * from the expression
+ */
+ static shared_ptr<XdmfArray>
+ evaluateExpression(std::string expression,
+ std::map<std::string, shared_ptr<XdmfArray> > variables);
+
+ /**
+ * Evaluates the operation specified using the two shared pointers to
+ * XdmfArrays provided.
+ * A list of valid operations is retrievable from the getSupportedOperations
+ * static method.
+ * None of the XdmfArrays provided are modified during the evaluation process.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declareoperation
+ * @until //#declareoperation
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#addOperation
+ * @until //#addOperation
+ * @skipline //#evaluateOperation
+ * @until //#evaluateOperation
+ * @skipline //#programend
+ * @until //#programend
+ * @skipline //#defineoperation
+ * @until //#defineoperation
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//defineoperation
+ * @until #//defineoperation
+ * @skipline #//programstart
+ * @until #//programstart
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//addOperation
+ * @until #//addOperation
+ * @skipline #//evaluateOperation
+ * @until #//evaluateOperation
+ *
+ * @param val1 The first array being evaluated
+ * @param val2 The second array being evaluated
+ * @param operation A character specifying the operation performed
+ * @return A shared pointer to the Xdmf Array that results
+ * from the calculation
+ */
+ static shared_ptr<XdmfArray>
+ evaluateOperation(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2,
+ char operation);
+
+ /**
+ * Evaluates the function specified using the vector of XdmfArrays provided.
+ * None of the XdmfArrays provided are modified during the evaluation process.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#declarefunction
+ * @until //#declarefunction
+ * @skipline //#programstart
+ * @until //#programstart
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#addFunction
+ * @until //#addFunction
+ * @skipline //#evaluateFunction
+ * @until //#evaluateFunction
+ * @skipline //#programend
+ * @until //#programend
+ * @skipline //#definefunction
+ * @until //#definefunction
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//definefunction
+ * @until #//definefunction
+ * @skipline #//programstart
+ * @until #//programstart
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//addFunction
+ * @until #//addFunction
+ * @skipline #//evaluateFunction
+ * @until #//evaluateFunction
+ *
+ * @param valueVector A vector containing the arrays to be used
+ * @param functionName The string associated with the function being called
+ * @return The result of the function being called,
+ * a scalar will be returned as an XdmfArray with one value
+ */
+ static shared_ptr<XdmfArray>
+ evaluateFunction(std::vector<shared_ptr<XdmfArray> > valueVector,
+ std::string functionName);
+
+ /**
+ * Sets the expression that the function will evaluate.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#setExpression
+ * @until //#setExpression
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//setExpression
+ * @until #//setExpression
+ *
+ * @return The expression that the function is currently using to evaluate
+ */
+ std::string getExpression() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ virtual std::string getItemTag() const;
+
+ /**
+ * Gets the priority of operation whose associated character is provided.
+ * Returns -1 if the operation is not supported.
+ * The higher the value the earlier that operation is evaluated
+ * during evaluateExpression.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#getOperationPriority
+ * @until //#getOperationPriority
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//getOperationPriority
+ * @until #//getOperationPriority
+ *
+ * @param operation The character associated with the operation
+ * to be checked
+ * @return The priority of the operation
+ */
+ static int getOperationPriority(char operation);
+
+ /**
+ * Gets a string that contains all the characters of the supported operations.
+ * Parenthesis are included for grouping purposes in expressions.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#getSupportedOperations
+ * @until //#getSupportedOperations
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//getSupportedOperations
+ * @until #//getSupportedOperations
+ *
+ * @return A string containing the characters for all supported operations
+ */
+ static const std::string getSupportedOperations();
+
+ /**
+ * Gets a string that contains all the characters of the supported operations.
+ * Parenthesis are included for grouping purposes in expressions.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#getSupportedFunctions
+ * @until //#getSupportedFunctions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//getSupportedFunctions
+ * @until #//getSupportedFunctions
+ *
+ * @return A vector containing the strings associated with all valid functions
+ */
+ static const std::vector<std::string> getSupportedFunctions();
+
+ /**
+ * Gets a string that contains all strings that are viable for use when mapping
+ * to scalars (which are stored in XdmfArrays of size 1) for the
+ * evaluateExpression function.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#getValidDigitChars
+ * @until //#getValidDigitChars
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//getValidDigitChars
+ * @until #//getValidDigitChars
+ *
+ * @return A string containing all valid variable characters
+ */
+ static const std::string getValidDigitChars();
+
+ /**
+ * Gets a string that contains all strings that are viable for use when mapping
+ * to shared pointers of XdmfArrays for the evaluateExpression function.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#getValidVariableChars
+ * @until //#getValidVariableChars
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//getValidVariableChars
+ * @until #//getValidVariableChars
+ *
+ * @return A string containing all valid variable characters
+ */
+ static const std::string getValidVariableChars();
+
+ /**
+ * Gets the array associated with the provided string out of the function's
+ * variable list.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#insertVariable
+ * @until //#insertVariable
+ * @skipline //#getVariable
+ * @until //#getVariable
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//insertVariable
+ * @until #//insertVariable
+ * @skipline #//getVariable
+ * @until #//getVariable
+ *
+ * @param key The string that is associated with the array to be retrieved
+ * @return The array that corresponds with the key provided.
+ */
+ shared_ptr<XdmfArray> getVariable(std::string key);
+
+ /**
+ * Gets a vector containing all the keys accociated with arrays for this function.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#insertVariable
+ * @until //#insertVariable
+ * @skipline //#getVariableList
+ * @until //#getVariableList
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//insertVariable
+ * @until #//insertVariable
+ * @skipline #//getVariableList
+ * @until #//getVariableList
+ *
+ * @return A vector of all the keys for this function
+ */
+ std::vector<std::string> getVariableList();
+
+ /**
+ * Joins the two provided arrays while interspercing their values evenly.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#interlace
+ * @until //#interlace
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//interlace
+ * @until #//interlace
+ *
+ * @param val1 The first array being evaluated
+ * @param val2 The second array being evaluated
+ * @return The interlaced arrays
+ */
+ static shared_ptr<XdmfArray>
+ interlace(shared_ptr<XdmfArray> val1,
+ shared_ptr<XdmfArray> val2);
+
+ /**
+ * Adds a new variable to the list of variables that the Function will use.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#insertVariable
+ * @until //#insertVariable
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//insertVariable
+ * @until #//insertVariable
+ *
+ * @param key The string to be associated with the provided array
+ * @param value The value of the variable when evaluated
+ */
+ void insertVariable(std::string key, shared_ptr<XdmfArray> value);
+
+ /**
+ * Concatenates all provided arrays in order provided.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#join
+ * @until //#join
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//join
+ * @until #//join
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the combined values
+ */
+ static shared_ptr<XdmfArray> join(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the log of all the values in that array. If a second array is provided
+ * it specifies the base for the log used. Default is natural log.
+ *
+ * If the first array has one value an array is generated using a log
+ * whose base is specified in the second array.
+ *
+ * If the second array has one value. A log of that base is applied to
+ * all values of the first array.
+ *
+ * If both arrays have the same number of values, the
+ * log of the base specified by the value of the same index
+ * in the second array is used.
+ *
+ * An error is thrown if the array sizes are both large than 1
+ * and do not match.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#log
+ * @until //#log
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//log
+ * @until #//log
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the log
+ * of the values of the first array
+ */
+ static shared_ptr<XdmfArray> log(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the arrays provided and multiplies the first one by the second,
+ * returning the result.
+ *
+ * If the first array has one value an array is generated
+ * by multiplying it by each value of the second array.
+ *
+ * If the second array has one value. Each value in the
+ * first array is multiplied by that value.
+ *
+ * If both arrays have the same number of values, each value of
+ * the first array is multiplied by the value of the second array
+ * with the same index.
+ *
+ * An error is thrown if the array sizes are both large than 1
+ * and do not match.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#multiplication
+ * @until //#multiplication
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//multiplication
+ * @until #//multiplication
+ *
+ * @param val1 The first array to be used
+ * @param val2 The second array to be used
+ * @return An XdmfArray containing the products
+ * of the multiplication of the arrays
+ */
+ static shared_ptr<XdmfArray> multiplication(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2);
+
+ /**
+ * Parses the expression that the function contains and generates an array
+ * containing the values that the function produces.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//read
+ * @until #//read
+ */
+ virtual shared_ptr<XdmfArray> read() const;
+
+ /**
+ * Removes a variable from the function if it exists.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#insertVariable
+ * @until //#insertVariable
+ * @skipline //#removeVariable
+ * @until //#removeVariable
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//insertVariable
+ * @until #//insertVariable
+ * @skipline #//removeVariable
+ * @until #//removeVariable
+ *
+ * @param key The string to be associated with the provided array
+ */
+ void removeVariable(std::string key);
+
+ /**
+ * Sets the expression that the function will evaluate.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#initexpression
+ * @until //#initexpression
+ * @skipline //#setExpression
+ * @until //#setExpression
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//initexpression
+ * @until #//initexpression
+ * @skipline #//setExpression
+ * @until #//setExpression
+ *
+ * @param newExpression The expression that the function is to evaluate
+ */
+ void setExpression(std::string newExpression);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the sin of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#sin
+ * @until //#sin
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//sin
+ * @until #//sin
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the sin of the
+ * values of the first array
+ */
+ static shared_ptr<XdmfArray> sin(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the square root of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#sqrt
+ * @until //#sqrt
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//sqrt
+ * @until #//sqrt
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the square root
+ * of the values of the first array
+ */
+ static shared_ptr<XdmfArray> sqrt(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the arrays provided and subtracts the second from the first,
+ * returning the result.
+ *
+ * If the first array has one value an array is generated
+ * by subtracting each value of the second array.
+ *
+ * If the second array has one value. That value is
+ * subtracted from each value of the first array.
+ *
+ * If both arrays have the same number of values, each value of
+ * the second array is subtracted from the value of the first array
+ * with the same index.
+ *
+ * An error is thrown if the array sizes are both large than 1
+ * and do not match.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#subtraction
+ * @until //#subtraction
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//subtraction
+ * @until #//subtraction
+ *
+ * @param val1 The array to be subtracted from
+ * @param val2 The array to be subtracted
+ * @return An XdmfArray containing the difference
+ * of the arrays
+ */
+ static shared_ptr<XdmfArray> subtraction(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2);
+
+ /**
+ * Adds together all the values contained in the provided arrays.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#valueinit
+ * @until //#valueinit
+ * @skipline //#sum
+ * @until //#sum
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//valueinit
+ * @until #//valueinit
+ * @skipline #//sum
+ * @until #//sum
+ *
+ * @param values A vector containing the arrays to be used
+ * @return An XdmfArray containing one value which is the total
+ * of all the values contained within the provided arrays
+ */
+ static shared_ptr<XdmfArray>
+ sum(std::vector<shared_ptr<XdmfArray> > values);
+
+ /**
+ * Takes the first array provided and returns an array containing
+ * the tan of all the values in that array.
+ *
+ * Example of Use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfFunction.cpp
+ * @skipline //#tan
+ * @until //#tan
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleFunction.py
+ * @skipline #//tan
+ * @until #//tan
+ *
+ * @param values A vector containing the array to be used
+ * @return An XdmfArray containing the tan of the
+ * values of the first array
+ */
+ static shared_ptr<XdmfArray> tan(std::vector<shared_ptr<XdmfArray> > values);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfFunction(XdmfFunction &);
+
+protected:
+
+ XdmfFunction();
+ XdmfFunction(std::string newExpression,
+ std::map<std::string,
+ shared_ptr<XdmfArray> > newVariables);
+
+private:
+
+ XdmfFunction(const XdmfFunction &); // Not implemented.
+ void operator=(const XdmfFunction &); // Not implemented.
+
+ std::map<std::string, shared_ptr<XdmfArray> > mVariableList;
+ std::string mExpression;
+
+ static std::string mSupportedOperations;
+ static const std::string mValidVariableChars;
+ static const std::string mValidDigitChars;
+ static std::map<char, int> mOperationPriority;
+
+
+ static std::map<std::string, shared_ptr<XdmfFunctionInternal> > arrayFunctions;
+ static std::map<char, shared_ptr<XdmfOperationInternal> > operations;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct XDMFFUNCTION; // Simply as a typedef to ensure correct typing
+typedef struct XDMFFUNCTION XDMFFUNCTION;
+
+XDMFCORE_EXPORT XDMFFUNCTION * XdmfFunctionNew();
+
+XDMFCORE_EXPORT XDMFFUNCTION * XdmfFunctionNewInit(char * newExpression, char ** keys, XDMFARRAY ** values, int numVariables);
+
+XDMFCORE_EXPORT int XdmfFunctionAddFunction(char * name, XDMFARRAY *(*functionref)(XDMFARRAY **, unsigned int), int * status);
+
+XDMFCORE_EXPORT int XdmfFunctionAddOperation(char newoperator, XDMFARRAY *(*operationref)(XDMFARRAY *, XDMFARRAY *), int priority, int * status);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionAverage(XDMFARRAY ** values, int numValues);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionChunk(XDMFARRAY * val1, XDMFARRAY * val2, int * status);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionEvaluateExpression(char * expression, char ** keys, XDMFARRAY ** values, int numVariables, int * status);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionEvaluateOperation(XDMFARRAY * val1, XDMFARRAY * val2, char operation, int * status);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionEvaluateFunction(XDMFARRAY ** valueVector, int numValues, char * functionName, int * status);
+
+XDMFCORE_EXPORT char * XdmfFunctionGetExpression(XDMFFUNCTION * function);
+
+XDMFCORE_EXPORT unsigned int XdmfFunctionGetNumberVariables(XDMFFUNCTION * function);
+
+XDMFCORE_EXPORT int XdmfFunctionGetOperationPriority(char operation);
+
+XDMFCORE_EXPORT char * XdmfFunctionGetSupportedOperations();
+
+XDMFCORE_EXPORT char ** XdmfFunctionGetSupportedFunctions();
+
+XDMFCORE_EXPORT unsigned int XdmfFunctionGetNumberSupportedFunctions();
+
+XDMFCORE_EXPORT char * XdmfFunctionGetValidDigitChars();
+
+XDMFCORE_EXPORT char * XdmfFunctionGetValidVariableChars();
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionGetVariable(XDMFFUNCTION * function, char * key);
+
+XDMFCORE_EXPORT char ** XdmfFunctionGetVariableList(XDMFFUNCTION * function);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionInterlace(XDMFARRAY * val1, XDMFARRAY * val2, int * status);
+
+XDMFCORE_EXPORT void XdmfFunctionInsertVariable(XDMFFUNCTION * function, char * key, XDMFARRAY * value, int passControl);
+
+XDMFCORE_EXPORT void XdmfFunctionRemoveVariable(XDMFFUNCTION * function, char * key);
+
+XDMFCORE_EXPORT void XdmfFunctionSetExpression(XDMFFUNCTION * function, char * newExpression, int * status);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfFunctionSum(XDMFARRAY ** values, int numValues);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfFunction, XDMFFUNCTION, XDMFCORE)
+XDMF_ARRAYREFERENCE_C_CHILD_DECLARE(XdmfFunction, XDMFFUNCTION, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFFUNCTION_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* Xdmf */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHDF5Controller.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <vtk_hdf5.h>
+#include <numeric>
+#include <sstream>
+#include "string.h"
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfHDF5Controller.hpp"
+#include "XdmfSystemUtils.hpp"
+
+unsigned int XdmfHDF5Controller::mMaxOpenedFiles = 0;
+static std::map<std::string, hid_t> mOpenFiles;
+std::map<std::string, unsigned int> XdmfHDF5Controller::mOpenFileUsage;
+
+shared_ptr<XdmfHDF5Controller>
+XdmfHDF5Controller::New(const std::string & hdf5FilePath,
+ const std::string & dataSetPath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions)
+{
+ shared_ptr<XdmfHDF5Controller>
+ p(new XdmfHDF5Controller(hdf5FilePath,
+ dataSetPath,
+ type,
+ start,
+ stride,
+ dimensions,
+ dataspaceDimensions));
+ return p;
+}
+
+XdmfHDF5Controller::XdmfHDF5Controller(const std::string & hdf5FilePath,
+ const std::string & dataSetPath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions) :
+ XdmfHeavyDataController(hdf5FilePath,
+ type,
+ start,
+ stride,
+ dimensions,
+ dataspaceDimensions),
+ mDataSetPath(dataSetPath),
+ mDataSetPrefix(""),
+ mDataSetId(-1)
+{
+ unsigned int i = 0;
+ for (; i < mDataSetPath.size(); ++i) {
+ if (mDataSetPath[(mDataSetPath.size() - 1) - i] != '0' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '1' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '2' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '3' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '4' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '5' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '6' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '7' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '8' &&
+ mDataSetPath[(mDataSetPath.size() - 1) - i] != '9') {
+ break;
+ }
+ }
+ unsigned int endOfPrefix = (mDataSetPath.size()) - i;
+ mDataSetPrefix = mDataSetPath.substr(0, endOfPrefix);
+ if (mDataSetPrefix.compare(mDataSetPath) != 0) {
+ mDataSetId = atoi(mDataSetPath.substr(endOfPrefix).c_str());
+ }
+}
+
+XdmfHDF5Controller::XdmfHDF5Controller(const XdmfHDF5Controller& refController):
+ XdmfHeavyDataController(refController),
+ mDataSetPath(refController.getDataSetPath()),
+ mDataSetPrefix(refController.mDataSetPrefix),
+ mDataSetId(refController.mDataSetId)
+{
+}
+
+XdmfHDF5Controller::~XdmfHDF5Controller()
+{
+}
+
+void
+XdmfHDF5Controller::closeFiles()
+{
+ for (std::map<std::string, hid_t>::iterator closeIter = mOpenFiles.begin();
+ closeIter != mOpenFiles.end();
+ ++closeIter) {
+ H5Fclose(closeIter->second);
+ }
+ mOpenFiles.clear();
+ mOpenFileUsage.clear();
+}
+
+std::string
+XdmfHDF5Controller::getDataSetPath() const
+{
+ return mDataSetPath;
+}
+
+const std::string
+XdmfHDF5Controller::getDataSetPrefix() const
+{
+ return mDataSetPrefix;
+}
+
+int
+XdmfHDF5Controller::getDataSetId() const
+{
+ return mDataSetId;
+}
+
+std::string
+XdmfHDF5Controller::getDescriptor() const
+{
+ return ":" + mDataSetPath;
+}
+
+std::string
+XdmfHDF5Controller::getName() const
+{
+ return "HDF";
+}
+
+unsigned int
+XdmfHDF5Controller::getMaxOpenedFiles()
+{
+ return XdmfHDF5Controller::mMaxOpenedFiles;
+}
+
+void
+XdmfHDF5Controller::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties["Format"] = this->getName();
+}
+
+void
+XdmfHDF5Controller::read(XdmfArray * const array)
+{
+ this->read(array, H5P_DEFAULT);
+}
+
+void
+XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
+{
+ herr_t status;
+ hid_t hdf5Handle;
+ if (XdmfHDF5Controller::mMaxOpenedFiles == 0) {
+ hdf5Handle = H5Fopen(mFilePath.c_str(), H5F_ACC_RDONLY, fapl);
+ }
+ else {
+ std::map<std::string, hid_t>::iterator checkOpen = mOpenFiles.find(mFilePath);
+ if (checkOpen == mOpenFiles.end()) {
+ // If the number of open files would become larger than allowed
+ if (mOpenFiles.size() + 1 > mMaxOpenedFiles) {
+ // Close least used one
+ std::map<std::string, unsigned int>::iterator walker = mOpenFileUsage.begin();
+ std::string oldestFile = walker->first;
+ while (walker != mOpenFileUsage.end()) {
+ // We want the file with the fewest accesses
+ // If two are tied, we use the older one
+ if (mOpenFileUsage[oldestFile] > walker->second) {
+ oldestFile = walker->first;
+ }
+ ++walker;
+ }
+ status = H5Fclose(mOpenFiles[oldestFile]);
+ mOpenFiles.erase(oldestFile);
+ mOpenFileUsage.erase(oldestFile);
+ }
+ hdf5Handle = H5Fopen(mFilePath.c_str(), H5F_ACC_RDONLY, fapl);
+ mOpenFiles[mFilePath] = hdf5Handle;
+ mOpenFileUsage[mFilePath] = 1;
+ }
+ else {
+ hdf5Handle = checkOpen->second;
+ mOpenFileUsage[mFilePath]++;
+ }
+ }
+
+ const hid_t dataset = H5Dopen(hdf5Handle, mDataSetPath.c_str(), H5P_DEFAULT);
+ const hid_t dataspace = H5Dget_space(dataset);
+
+ const unsigned int dataspaceDims = H5Sget_simple_extent_ndims(dataspace);
+ const std::vector<hsize_t> count(mDimensions.begin(), mDimensions.end());
+
+ if(dataspaceDims != mDimensions.size()) {
+ // special case where the number of dimensions of the hdf5 dataset
+ // does not equal the number of dimensions in the light data
+ // description - in this case we cannot properly take a hyperslab
+ // selection, so we assume we are reading the entire dataset and
+ // check whether that is ok to do
+ const int numberValuesHDF5 = H5Sget_select_npoints(dataspace);
+ const int numberValuesXdmf =
+ std::accumulate(mDimensions.begin(),
+ mDimensions.end(),
+ 1,
+ std::multiplies<unsigned int>());
+ if(numberValuesHDF5 != numberValuesXdmf) {
+ XdmfError::message(XdmfError::FATAL,
+ "Number of dimensions in light data description in "
+ "Xdmf does not match number of dimensions in hdf5 "
+ "file.");
+ }
+ }
+ else {
+ const std::vector<hsize_t> start(mStart.begin(), mStart.end());
+ const std::vector<hsize_t> stride(mStride.begin(), mStride.end());
+
+ status = H5Sselect_hyperslab(dataspace,
+ H5S_SELECT_SET,
+ &start[0],
+ &stride[0],
+ &count[0],
+ NULL);
+ }
+
+ const hssize_t numVals = H5Sget_select_npoints(dataspace);
+ hid_t memspace = H5Screate_simple(mDimensions.size(),
+ &count[0],
+ NULL);
+
+ /* status = H5Sselect_hyperslab(memspace,
+ H5S_SELECT_SET,
+ &memStart[0],
+ &memStride[0],
+ &memCount[0],
+ NULL);*/
+
+ hid_t datatype = H5T_NO_CLASS;
+ bool closeDatatype = false;
+ if(mType == XdmfArrayType::Int8()) {
+ datatype = H5T_NATIVE_CHAR;
+ }
+ else if(mType == XdmfArrayType::Int16()) {
+ datatype = H5T_NATIVE_SHORT;
+ }
+ else if(mType == XdmfArrayType::Int32()) {
+ datatype = H5T_NATIVE_INT;
+ }
+ else if(mType == XdmfArrayType::Int64()) {
+ datatype = H5T_NATIVE_LONG;
+ }
+ else if(mType == XdmfArrayType::Float32()) {
+ datatype = H5T_NATIVE_FLOAT;
+ }
+ else if(mType == XdmfArrayType::Float64()) {
+ datatype = H5T_NATIVE_DOUBLE;
+ }
+ else if(mType == XdmfArrayType::UInt8()) {
+ datatype = H5T_NATIVE_UCHAR;
+ }
+ else if(mType == XdmfArrayType::UInt16()) {
+ datatype = H5T_NATIVE_USHORT;
+ }
+ else if(mType == XdmfArrayType::UInt32()) {
+ datatype = H5T_NATIVE_UINT;
+ }
+ else if(mType == XdmfArrayType::UInt64()) {
+ datatype = H5T_NATIVE_UINT64;
+ }
+ else if(mType == XdmfArrayType::String()) {
+ datatype = H5Tcopy(H5T_C_S1);
+ H5Tset_size(datatype, H5T_VARIABLE);
+ closeDatatype = true;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Unknown XdmfArrayType encountered in hdf5 "
+ "controller.");
+ }
+
+ array->initialize(mType, mDimensions);
+
+ if(numVals != array->getSize()) {
+ std::stringstream errOut;
+ errOut << "Number of values in hdf5 dataset (" << numVals;
+ errOut << ")\ndoes not match allocated size in XdmfArray (" << array->getSize() << ").";
+ XdmfError::message(XdmfError::FATAL,
+ errOut.str());
+ }
+ if(closeDatatype) {
+ char ** data = new char*[numVals];
+ status = H5Dread(dataset,
+ datatype,
+ memspace,
+ dataspace,
+ H5P_DEFAULT,
+ data);
+ for(hssize_t i=0; i<numVals; ++i) {
+ array->insert<std::string>(i, data[i]);
+ }
+ status = H5Dvlen_reclaim(datatype,
+ dataspace,
+ H5P_DEFAULT,
+ data);
+ delete [] data;
+ }
+ else {
+ status = H5Dread(dataset,
+ datatype,
+ memspace,
+ dataspace,
+ H5P_DEFAULT,
+ array->getValuesInternal());
+ }
+
+ status = H5Sclose(dataspace);
+ status = H5Sclose(memspace);
+ status = H5Dclose(dataset);
+ if(closeDatatype) {
+ status = H5Tclose(datatype);
+ }
+ if (XdmfHDF5Controller::mMaxOpenedFiles == 0) {
+ status = H5Fclose(hdf5Handle);
+ }
+}
+
+void
+XdmfHDF5Controller::setMaxOpenedFiles(unsigned int newMax)
+{
+ XdmfHDF5Controller::mMaxOpenedFiles = newMax;
+}
+
+// C Wrappers
+
+XDMFHDF5CONTROLLER * XdmfHDF5ControllerNew(char * hdf5FilePath,
+ char * dataSetPath,
+ int type,
+ unsigned int * start,
+ unsigned int * stride,
+ unsigned int * dimensions,
+ unsigned int * dataspaceDimensions,
+ unsigned int numDims,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfHDF5Controller> generatedController = XdmfHDF5Controller::New(std::string(hdf5FilePath), std::string(dataSetPath), buildType, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFHDF5CONTROLLER *)((void *)(new XdmfHDF5Controller(*generatedController.get())));
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfHDF5Controller> generatedController = XdmfHDF5Controller::New(std::string(hdf5FilePath), std::string(dataSetPath), buildType, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFHDF5CONTROLLER *)((void *)(new XdmfHDF5Controller(*generatedController.get())));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+char * XdmfHDF5ControllerGetDataSetPath(XDMFHDF5CONTROLLER * controller)
+{
+ char * returnPointer = strdup(((XdmfHDF5Controller *)(controller))->getDataSetPath().c_str());
+ return returnPointer;
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_HEAVYCONTROLLER_C_CHILD_WRAPPER(XdmfHDF5Controller, XDMFHDF5CONTROLLER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHDF5Controller.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFHDF5CONTROLLER_HPP_
+#define XDMFHDF5CONTROLLER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataController.hpp"
+
+#include "vtk_hdf5.h"
+
+#ifdef __cplusplus
+
+#include <map>
+
+/**
+ * @brief Couples an XdmfArray with HDF5 data stored on disk.
+ *
+ * Serves as an interface between data stored in XdmfArrays and data
+ * stored in hdf5 files on disk. When an Xdmf file is read from or
+ * written to disk an XdmfHDF5Controller is attached to
+ * XdmfArrays. This allows data to be released from memory but still
+ * be accessible or have its location written to light data.
+ */
+class XDMFCORE_EXPORT XdmfHDF5Controller : public XdmfHeavyDataController {
+
+public:
+
+ friend class XdmfHDF5Writer;
+
+ virtual ~XdmfHDF5Controller();
+
+ /**
+ * Create a new controller for an hdf5 data set on disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param hdf5FilePath the location of the hdf5 file the data set resides in.
+ * @param dataSetPath the location of the dataset within the hdf5 file.
+ * @param type the data type of the dataset to read.
+ * @param start the offset of the starting element in each dimension in
+ * the hdf5 data set.
+ * @param stride the number of elements to move in each dimension from the
+ * hdf5 data set.
+ * @param dimensions the number of elements to select in each
+ * dimension from the hdf5 data set. (size in each dimension)
+ * @param dataspaceDimensions the number of elements in the entire
+ * hdf5 data set (may be larger than dimensions if using
+ * hyperslabs).
+ *
+ * @return New HDF5 Controller.
+ */
+ static shared_ptr<XdmfHDF5Controller>
+ New(const std::string & hdf5FilePath,
+ const std::string & dataSetPath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions);
+
+ /**
+ * Closes the files currently open for reading.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#closeFiles
+ * @until //#closeFiles
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//closeFiles
+ * @until #//closeFiles
+ */
+ static void closeFiles();
+
+ /**
+ * Get the path of the data set within the heavy data file owned by
+ * this controller.
+ * For "/home/output.h5:/foo/data" this is "/foo/data"
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDataSetPath
+ * @until //#getDataSetPath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDataSetPath
+ * @until #//getDataSetPath
+ *
+ * @return A std::string containing the path of the data set.
+ */
+ std::string getDataSetPath() const;
+
+ virtual std::string getDescriptor() const;
+
+ virtual std::string getName() const;
+
+ /**
+ * Gets the maximum number of hdf5 files that are allowed to be open at once.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#getMaxOpenedFiles
+ * @until //#getMaxOpenedFiles
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//getMaxOpenedFiles
+ * @until #//getMaxOpenedFiles
+ *
+ * @return The maximum number of hdf5 files
+ */
+ static unsigned int getMaxOpenedFiles();
+
+ virtual void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+ virtual void read(XdmfArray * const array);
+
+ /**
+ * Sets the maximum number of hdf5 files that are allowed to be open at once.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#setMaxOpenedFiles
+ * @until //#setMaxOpenedFiles
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//setMaxOpenedFiles
+ * @until #//setMaxOpenedFiles
+ *
+ * @param newMax The new maximum amount of files to be open
+ */
+ static void setMaxOpenedFiles(unsigned int newMax);
+
+ XdmfHDF5Controller(const XdmfHDF5Controller &);
+
+protected:
+
+ XdmfHDF5Controller(const std::string & hdf5FilePath,
+ const std::string & dataSetPath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions);
+
+ const std::string getDataSetPrefix() const;
+ int getDataSetId() const;
+
+ void read(XdmfArray * const array, const int fapl);
+
+private:
+
+ void operator=(const XdmfHDF5Controller &); // Not implemented.
+
+ const std::string mDataSetPath;
+
+ std::string mDataSetPrefix;
+ int mDataSetId;
+
+ static std::map<std::string, unsigned int> mOpenFileUsage;
+ // When set to 0 there will be no files that stay open after a read
+ static unsigned int mMaxOpenedFiles;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct XDMFHDF5CONTROLLER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFHDF5CONTROLLER XDMFHDF5CONTROLLER;
+
+XDMFCORE_EXPORT XDMFHDF5CONTROLLER * XdmfHDF5ControllerNew(char * hdf5FilePath,
+ char * dataSetPath,
+ int type,
+ unsigned int * start,
+ unsigned int * stride,
+ unsigned int * dimensions,
+ unsigned int * dataspaceDimensions,
+ unsigned int numDims,
+ int * status);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMFCORE_EXPORT char * XdmfHDF5ControllerGetDataSetPath(XDMFHDF5CONTROLLER * controller);
+
+XDMF_HEAVYCONTROLLER_C_CHILD_DECLARE(XdmfHDF5Controller, XDMFHDF5CONTROLLER, XDMFCORE)
+
+#define XDMF_HDF5CONTROLLER_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT char * ClassName##GetDataSetPath( CClassName * controller);
+
+#define XDMF_HDF5CONTROLLER_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+char * ClassName##GetDataSetPath( CClassName * controller) \
+{ \
+ return XdmfHDF5ControllerGetDataSetPath((XDMFHDF5CONTROLLER *)((void *)controller)); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFHDF5CONTROLLER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHDF5Writer.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <vtk_hdf5.h>
+#include <sstream>
+#include <cstdio>
+#include <cmath>
+#include <set>
+#include <list>
+#include <string.h>
+#include "XdmfItem.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfHDF5Controller.hpp"
+#include "XdmfHDF5Writer.hpp"
+#include "XdmfSystemUtils.hpp"
+
+namespace {
+
+ const static unsigned int DEFAULT_CHUNK_SIZE = 1000;
+
+}
+
+XdmfHDF5Writer::XdmfHDF5WriterImpl::XdmfHDF5WriterImpl():
+ mHDF5Handle(-1),
+ mFapl(H5P_DEFAULT),
+ mChunkSize(DEFAULT_CHUNK_SIZE),
+ mOpenFile(""),
+ mDepth(0)
+{
+};
+
+XdmfHDF5Writer::XdmfHDF5WriterImpl::~XdmfHDF5WriterImpl()
+{
+ closeFile();
+};
+
+void
+XdmfHDF5Writer::XdmfHDF5WriterImpl::closeFile()
+{
+ if(mHDF5Handle >= 0) {
+ H5Fclose(mHDF5Handle);
+ mHDF5Handle = -1;
+ }
+ mOpenFile = "";
+};
+
+int
+XdmfHDF5Writer::XdmfHDF5WriterImpl::openFile(const std::string & filePath,
+ const int mDataSetId)
+{
+ if(mHDF5Handle >= 0) {
+ // Perhaps we should throw a warning.
+ closeFile();
+ }
+ // Save old error handler and turn off error handling for now
+ H5E_auto_t old_func;
+ void * old_client_data;
+ H5Eget_auto(0, &old_func, &old_client_data);
+ H5Eset_auto2(0, NULL, NULL);
+
+ int toReturn = 0;
+
+ mOpenFile.assign(filePath);
+
+ if(H5Fis_hdf5(filePath.c_str()) > 0) {
+ mHDF5Handle = H5Fopen(filePath.c_str(),
+ H5F_ACC_RDWR,
+ mFapl);
+ if(mDataSetId == 0) {
+ hsize_t numObjects;
+ /*herr_t status = */H5Gget_num_objs(mHDF5Handle,
+ &numObjects);
+ toReturn = numObjects;
+ }
+ else {
+ toReturn = mDataSetId;
+ }
+ }
+ else {
+ mHDF5Handle = H5Fcreate(filePath.c_str(),
+ H5F_ACC_TRUNC,
+ H5P_DEFAULT,
+ mFapl);
+ }
+
+ // Restore previous error handler
+ H5Eset_auto2(0, old_func, old_client_data);
+
+ return toReturn;
+}
+
+shared_ptr<XdmfHDF5Writer>
+XdmfHDF5Writer::New(const std::string & filePath,
+ const bool clobberFile)
+{
+ if(clobberFile) {
+ std::remove(filePath.c_str());
+ }
+ shared_ptr<XdmfHDF5Writer> p(new XdmfHDF5Writer(filePath));
+ return p;
+}
+
+//Set mUseDeflate(true), and mDeflateFactor(6) for default compression
+XdmfHDF5Writer::XdmfHDF5Writer(const std::string & filePath) :
+ XdmfHeavyDataWriter(filePath, 1, 800),
+ mImpl(new XdmfHDF5WriterImpl()),
+ mUseDeflate(false),
+ mDeflateFactor(0)
+{
+}
+
+//Set mUseDeflate(true), and mDeflateFactor(6) for default compression
+XdmfHDF5Writer::XdmfHDF5Writer(const XdmfHDF5Writer & writerRef) :
+ XdmfHeavyDataWriter(writerRef.getFilePath(), 1, 800),
+ mImpl(new XdmfHDF5WriterImpl()),
+ mUseDeflate(false),
+ mDeflateFactor(0)
+{
+}
+
+XdmfHDF5Writer::~XdmfHDF5Writer()
+{
+ delete mImpl;
+}
+
+void
+XdmfHDF5Writer::controllerSplitting(XdmfArray & array,
+ int & controllerIndexOffset,
+ shared_ptr<XdmfHeavyDataController> heavyDataController,
+ const std::string & checkFileName,
+ const std::string & checkFileExt,
+ const std::string & dataSetPath,
+ int dataSetId,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ std::list<std::string> & filesWritten,
+ std::list<std::string> & datasetsWritten,
+ std::list<int> & datasetIdsWritten,
+ std::list<void *> & arraysWritten,
+ std::list<std::vector<unsigned int> > & startsWritten,
+ std::list<std::vector<unsigned int> > & stridesWritten,
+ std::list<std::vector<unsigned int> > & dimensionsWritten,
+ std::list<std::vector<unsigned int> > & dataSizesWritten,
+ std::list<unsigned int> & arrayOffsetsWritten)
+{
+ // This is the file splitting algorithm
+ if (getFileSizeLimit() > 0) {
+ // Only if the file limit is positive, disabled if 0 or negative
+ unsigned int previousDataSize = 0;
+
+ std::vector<unsigned int> previousDimensions;
+ std::vector<unsigned int> previousDataSizes;
+ unsigned int amountAlreadyWritten = 0;
+ // Even though theoretically this could be an infinite loop
+ // if all possible files with the specified name are produced
+ // the chances of that happening are small.
+ // It can handle up to 65535 different files.
+ // This value may vary depending on the compiler and platform.
+ // The variable UINT_MAX holds the value in question.
+ // If all files are take up it will loop until a file opens up
+ // since adding past the max causes overflow.
+
+ unsigned int containedInController = 1;
+ for (unsigned int j = 0; j < dataspaceDimensions.size(); ++j) {
+ containedInController *= dataspaceDimensions[j];
+ }
+ int hyperslabSize = 0;
+ while (amountAlreadyWritten < containedInController) {
+
+ std::vector<unsigned int> partialStarts;
+ std::vector<unsigned int> partialStrides;
+ std::vector<unsigned int> partialDimensions;
+ std::vector<unsigned int> partialDataSizes;
+
+ std::stringstream testFile;
+ if (getFileIndex() == 0) {
+ // If sequentially named files need to be created or referenced
+ testFile << checkFileName << "." << checkFileExt;
+ }
+ else {
+ testFile << checkFileName << getFileIndex() << "." << checkFileExt;
+ }
+ FILE *checkFile = NULL;
+ unsigned int fileSize = 0;
+ // If the file doesn't exist the size is 0 because there's no data
+ // Get the file stream
+ checkFile = fopen(testFile.str().c_str(), "a");
+ if (checkFile != NULL) {
+ // Set the file pointer to end of file
+ fseek(checkFile, 0, SEEK_END);
+ // Get the file size, in bytes
+ fileSize = ftell(checkFile);
+
+ // If overwrite subtract previous data size.
+ if (mMode == Overwrite || mMode == Hyperslab) {
+ // Find previous data size
+ std::stringstream currentDataSetPath;
+ currentDataSetPath << dataSetPath;
+ if (dataSetId >= 0)
+ {
+ currentDataSetPath << dataSetId;
+ }
+ int checkfilesize = getDataSetSize(testFile.str(), currentDataSetPath.str());
+ if (checkfilesize < 0) {
+ checkfilesize = 0;
+ }
+ unsigned int checksize = (unsigned int)checkfilesize;
+ if (mMode == Overwrite) {
+ if (checksize > fileSize) {
+ fileSize = 0;
+ }
+ else {
+ fileSize = fileSize - checksize;
+ // Remove previous set's size, since it's overwritten
+ }
+ if (fileSize == 0) {
+ fileSize += getFileOverhead();
+ }
+ }
+ else if (mMode == Hyperslab) {
+ hyperslabSize = checksize;
+ }
+ }
+ if (fileSize == 0) {
+ fileSize += getFileOverhead();
+ }
+ fclose(checkFile);
+ }
+ else if (previousDataSize == 0) {
+ fileSize += getFileOverhead();
+ }
+ if (fileSize > (unsigned int)getFileSizeLimit()*(1024*1024)) {
+ fileSize = (unsigned int)getFileSizeLimit()*(1024*1024);
+ }
+ //Start of splitting section
+
+ // If needed split the written array
+ // into smaller arrays based on dimension blocks
+ // Working with strings has a more
+ // resource intensive version of this algorithm
+ // Size needed is equal to the dataspaceDimensions if in hyperslab mode
+ // otherwise is equal to the size of the written array
+ unsigned int remainingSize = 0;
+ unsigned int dataItemSize = 1;
+ if (array.getArrayType() == XdmfArrayType::String()) {
+ unsigned int remainingValues = 0;
+ unsigned int sizeArrayIndex = 0;
+ if (mMode == Hyperslab) {
+ remainingValues += 1;
+ sizeArrayIndex += 1;
+ for (unsigned int j = 0; j < dataspaceDimensions[j]; ++j) {
+ remainingValues *= dataspaceDimensions[j];
+ sizeArrayIndex *= dimensions[j];
+ }
+ }
+ else {
+ remainingValues += array.getSize();
+ sizeArrayIndex = amountAlreadyWritten;
+ }
+ remainingValues -= amountAlreadyWritten;
+ // Reduce by number of values already written
+ if (remainingValues == 0) {
+ // End if no remaining values
+ break;
+ }
+ // If remaining size is less than available space, just write all of what's left
+ // Calculate remaining size
+ for (unsigned int j = sizeArrayIndex; j < array.getSize(); ++j) {
+ remainingSize +=
+ (unsigned int)((double)(array.getValue<std::string>(j).size()) *
+ 8.0 * mCompressionRatio);
+ }
+ if (mMode == Hyperslab) {
+ // Size is estimated based on averages
+ remainingSize = (remainingSize /
+ (array.getSize() - sizeArrayIndex)) *
+ remainingValues;
+ }
+ }
+ else {
+ unsigned int remainingValues = 0;
+ if (mMode == Hyperslab) {
+ remainingValues += 1;
+ for (unsigned int j = 0; j < dataspaceDimensions.size(); ++j) {
+ remainingValues *= dataspaceDimensions[j];
+ }
+ }
+ else {
+ remainingValues += 1;
+ for (unsigned int j = 0; j < dimensions.size(); ++j) {
+ remainingValues *= dimensions[j];
+ }
+ }
+ if ((int)remainingValues - (int) amountAlreadyWritten < 0) {
+ remainingValues = 0;
+ }
+ else {
+ remainingValues -= amountAlreadyWritten;
+ }
+ // Reduce by number of values already written
+ if (remainingValues == 0) {//end if no remaining values
+ break;
+ }
+ dataItemSize =
+ (unsigned int)((double) (array.getArrayType()->getElementSize()) *
+ mCompressionRatio);
+ // If remaining size is less than available space, just write all of what's left
+ remainingSize = remainingValues * dataItemSize;
+ }
+ if (remainingSize + previousDataSize + fileSize - (hyperslabSize * dataItemSize)
+ <= (unsigned int)getFileSizeLimit()*(1024*1024)) {
+ // If the array hasn't been split
+ if (amountAlreadyWritten == 0) {
+ // Just pass all data to the partial vectors
+ for (unsigned int j = 0; j < dimensions.size(); ++j) {
+ // Done using a loop so that data is copied, not referenced
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ partialDimensions.push_back(dimensions[j]);
+ partialDataSizes.push_back(dataspaceDimensions[j]);
+ }
+ }
+ else {
+ // If the array has been split
+ int dimensionIndex = previousDimensions.size() - 1;
+ // Loop previous dimensions in
+ int j = 0;
+ for (j = 0; j < dimensionIndex; ++j) {
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ partialDimensions.push_back(dimensions[j]);
+ partialDataSizes.push_back(dataspaceDimensions[j]);
+ }
+ if (mMode == Hyperslab) {
+ int newStart = (start[j] +
+ stride[j] * previousDimensions[j])
+ - previousDataSizes[j];
+ while (newStart < 0) {
+ newStart += stride[j];
+ }
+ partialStarts.push_back(newStart);
+ // Stride should not change in this algorithm
+ partialStrides.push_back(stride[j]);
+ // Total up number of blocks for
+ // the higher dimesions and subtract the amount already written
+ unsigned int dimensiontotal = dimensions[j];
+ unsigned int dataspacetotal = dataspaceDimensions[j];
+ for (unsigned int k = j + 1; k < dimensions.size(); ++k) {
+ dimensiontotal *= dimensions[k];
+ dataspacetotal *= dataspaceDimensions[k];
+ }
+ if (previousDimensions.size() > 0) {
+ partialDimensions.push_back(dimensiontotal-previousDimensions[j]);
+ }
+ else {
+ partialDimensions.push_back(dimensiontotal);
+ }
+ if (previousDataSizes.size() > 0) {
+ partialDataSizes.push_back(dataspacetotal-previousDataSizes[j]);
+ }
+ else {
+ partialDataSizes.push_back(dataspacetotal);
+ }
+ }
+ else {
+ // Start and stride are not used outside of hyperslab
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ // Total up number of blocks for
+ // the higher dimesions and subtract the amount already written
+ // since it isn't hyperslab dimensions
+ // and dataspacedimensions should be the same
+ unsigned int dimensiontotal = dimensions[j];
+ for (unsigned int k = j + 1; k < dimensions.size(); ++k) {
+ dimensiontotal *= dimensions[k];
+ }
+ if (previousDimensions.size() > 0) {
+ partialDimensions.push_back(dimensiontotal-previousDimensions[j]);
+ }
+ else {
+ partialDimensions.push_back(dimensiontotal);
+ }
+ if (previousDataSizes.size() > 0) {
+ partialDataSizes.push_back(dimensiontotal-previousDataSizes[j]);
+ }
+ else {
+ partialDataSizes.push_back(dimensiontotal);
+ }
+ }
+ }
+ }
+ else {
+ // Otherwise, take remaining size
+ // and start removing dimensions until the dimension block is less
+ // then take a fraction of the dimension
+ // Calculate the number of values of the data type you're using will fit
+ unsigned int usableSpace = (getFileSizeLimit()*(1024*1024) -
+ (fileSize + previousDataSize)) / dataItemSize;
+ if ((unsigned int)getFileSizeLimit()*(1024*1024) < previousDataSize + fileSize) {
+ usableSpace = 0;
+ }
+ usableSpace += hyperslabSize;
+ // If the array hasn't been split
+ if (amountAlreadyWritten == 0) {
+ // See if it will fit in the next file
+ // If it will just go to the next file
+ // Otherwise split it.
+ if (remainingSize + getFileOverhead() >
+ (unsigned int)getFileSizeLimit()*(1024*1024)
+ && usableSpace > 0) {
+ if (getAllowSetSplitting()) {
+ // Figure out the size of the largest block that will fit.
+ unsigned int blockSizeSubtotal = 1;
+ unsigned int dimensionIndex = 0;
+ if (array.getArrayType() == XdmfArrayType::String()) {
+ unsigned int dimensionSizeTotal = 1;
+ unsigned int previousBlockSize = 0;
+ // Find the dimension that was split
+ while (dimensionIndex < dataspaceDimensions.size()
+ && blockSizeSubtotal <= usableSpace) {
+ // This is totally different for strings
+ dimensionSizeTotal *= dimensions[dimensionIndex];
+ previousBlockSize = blockSizeSubtotal;
+ blockSizeSubtotal = 0;
+ for (unsigned int k = 0; k < dimensionSizeTotal; ++k) {
+ if (amountAlreadyWritten + k > array.getSize()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Dimension in HDF5 Write.\n");
+ }
+ blockSizeSubtotal +=
+ array.getValue<std::string>(amountAlreadyWritten + k).size();
+ }
+ dimensionIndex++;
+ }
+ // It should end on the "blockSizeSubtotal <= usableSpace" statement
+ // the other half is for backup
+ // move back one dimension so we're working
+ // on the dimension that was split, not the one after it
+ dimensionIndex--;
+ blockSizeSubtotal = previousBlockSize;
+ }
+ else {
+ // Find the dimension that was split
+ while (dimensionIndex < dataspaceDimensions.size()
+ && blockSizeSubtotal <= usableSpace) {
+ blockSizeSubtotal *= dataspaceDimensions[dimensionIndex];
+ dimensionIndex++;
+ }
+ // It should end on the "blockSizeSubtotal <= arrayStartIndex" statement
+ // the other half is for backup
+ // Move back one dimension so we're working on the dimension that was split
+ // not the one after it
+ dimensionIndex--;
+ blockSizeSubtotal /= dataspaceDimensions[dimensionIndex];
+ }
+ // Determine how many of those blocks will fit
+ unsigned int numBlocks = usableSpace / blockSizeSubtotal;
+ // This should be less than the current value for the dimension
+ // Add dimensions as required.
+ unsigned int j = 0;
+ for (j = 0; j < dimensionIndex; ++j) {
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ partialDimensions.push_back(dimensions[j]);
+ partialDataSizes.push_back(dataspaceDimensions[j]);
+ }
+ if (start[j] > numBlocks) {
+ partialStarts.push_back(numBlocks-1);
+ }
+ else {
+ partialStarts.push_back(start[j]);
+ }
+ partialStrides.push_back(stride[j]);
+ partialDataSizes.push_back(numBlocks);
+ if (dimensions[j] == dataspaceDimensions[j]) {
+ // This is for non-hyperslab and specific cases of hyperslab
+ partialDimensions.push_back(numBlocks);
+ }
+ else {
+ // For hyperslab in general
+ // Determine how many values from the array will fit
+ // into the blocks being used with the dimensions specified
+ unsigned int displacement = numBlocks / stride[j];
+ if (((int)displacement * (int)stride[j])
+ + (start[j] % stride[j])
+ < numBlocks) {
+ displacement++;
+ }
+ displacement -= start[j]/stride[j];
+ if (start[j] > numBlocks) {
+ displacement = 0;
+ }
+ if (dimensions[j] <= displacement) {
+ // If there are less values than there are space for
+ // just write all of them.
+ partialDimensions.push_back(dimensions[j]);
+ }
+ else {
+ // Otherwise write what space allows for
+ partialDimensions.push_back(displacement);
+ }
+ }
+ }
+ else {
+ // Just pass all data to the partial vectors
+ for (unsigned int j = 0; j < dimensions.size(); ++j) {
+ // Done using a loop so that data is copied, not referenced
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ partialDimensions.push_back(dimensions[j]);
+ partialDataSizes.push_back(dataspaceDimensions[j]);
+ }
+ }
+ }
+ }
+ else {
+ // If the array has been split
+ // This case should not come up often
+ // as it requires truly gigantic data sets
+ // See if the remaining data will fit in the next file
+ // If yes, skip to it
+ // If no, split
+ if (remainingSize + getFileOverhead() >
+ (unsigned int)getFileSizeLimit()*(1024*1024)
+ && usableSpace > 0) {
+ // Figure out the size of the largest block that will fit.
+ unsigned int blockSizeSubtotal = 1;
+ unsigned int dimensionIndex = 0;
+ if (array.getArrayType() == XdmfArrayType::String()) {
+ unsigned int dimensionSizeTotal = 1;
+ unsigned int previousBlockSize = 0;
+ // Find the dimension that was split
+ while (dimensionIndex < dataspaceDimensions.size()
+ && blockSizeSubtotal <= usableSpace) {
+ // This is totally different for strings
+ dimensionSizeTotal *= dimensions[dimensionIndex];
+ previousBlockSize = blockSizeSubtotal;
+ blockSizeSubtotal = 0;
+ for (unsigned int k = 0; k < dimensionSizeTotal; ++k) {
+ if (amountAlreadyWritten + k > array.getSize()) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid Dimension in HDF5 Write.\n");
+ }
+ blockSizeSubtotal +=
+ array.getValue<std::string>(amountAlreadyWritten + k).size();
+ }
+ dimensionIndex++;
+ }
+ // It should end on the "blockSizeSubtotal <= usableSpace" statement
+ // the other half is for backup
+ // move back one dimension so we're working
+ // on the dimension that was split, not the one after it
+ dimensionIndex--;
+ blockSizeSubtotal = previousBlockSize;
+ }
+ else {
+ // Find the dimension that was split
+ while (dimensionIndex < dataspaceDimensions.size()
+ && blockSizeSubtotal <= usableSpace) {
+ blockSizeSubtotal *= dataspaceDimensions[dimensionIndex];
+ dimensionIndex++;
+ }
+ // It should end on the "blockSizeSubtotal <= arrayStartIndex" statement
+ // the other half is for backup
+ // Move back one dimension so we're working on the dimension that was split
+ // not the one after it
+ dimensionIndex--;
+ blockSizeSubtotal /= dataspaceDimensions[dimensionIndex];
+ }
+ unsigned int j = 0;
+ for (; j < dimensionIndex; ++j) {
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ partialDimensions.push_back(dimensions[j]);
+ partialDataSizes.push_back(dataspaceDimensions[j]);
+ }
+ // Continue if the block is smaller than the available size
+ if (blockSizeSubtotal <=usableSpace) {
+ // Find number of blocks that will fit
+ // This should be less than the current value for the dimension
+ unsigned int numBlocks = usableSpace / blockSizeSubtotal;
+ // Add dimensions to the partial vectors
+ if (mMode == Hyperslab) {
+ int newStart = (start[j] +
+ stride[j] * previousDimensions[j]) -
+ previousDataSizes[j];
+ while (newStart < 0) {
+ newStart += stride[j];
+ }
+ partialStarts.push_back(newStart);
+ // Stride should not change in this algorithm
+ partialStrides.push_back(stride[j]);
+ partialDataSizes.push_back(numBlocks);
+ // Determine how many values from the array will fit
+ // into the blocks being used
+ // with the dimensions specified
+ unsigned int displacement = (numBlocks - newStart)
+ / stride[j];
+ if (((int)displacement * (int)stride[j]) + (newStart % stride[j])
+ < numBlocks) {
+ displacement++;
+ }
+ displacement -= newStart/stride[j];
+ if (newStart > (int)numBlocks) {
+ displacement = 0;
+ }
+ if ((dimensions[j] - previousDimensions[j]) <= displacement) {
+ // If there are less values than there are space for
+ // just write all of them.
+ partialDimensions.push_back(dimensions[j] - previousDimensions[j]);
+ }
+ else {
+ // Otherwise write what space allows for
+ partialDimensions.push_back(displacement);
+ }
+ }
+ else {
+ // Start and stride are only specified in hyperslab
+ partialStarts.push_back(start[j]);
+ partialStrides.push_back(stride[j]);
+ partialDataSizes.push_back(numBlocks);
+ partialDimensions.push_back(numBlocks);
+ }
+ // Place dimensions into previous dimensions
+ // for later iterations
+ }
+ else {
+ // If this is larger than usable space, try the next file
+ // If moving to next file
+ // just do nothing and pass out of the if statement
+ // but also check if specified file size is too small
+ if ((unsigned int)getFileSizeLimit()*(1024*1024)
+ < blockSizeSubtotal) {
+ // This shouldn't ever trigger,
+ // but it's good to cover ourselves
+ // Throw an error if the block size won't work
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Dimension Block size"
+ " / Maximum File size mismatch.\n");
+ }
+ }
+ }
+ }
+ // Move to next file
+ setFileIndex(getFileIndex()+1);
+ }
+
+ if (partialDimensions.size() > 0) {
+ // Building the array to be written
+ int containedInDimensions = 1;
+ // Count moved
+ for (unsigned int j = 0 ; j < partialDimensions.size(); ++j) {
+ containedInDimensions *= partialDimensions[j];
+ }
+ // Starting index
+ int containedInPriorDimensions = controllerIndexOffset;
+ int startOffset = 1;
+ for (unsigned int j = 0; j < previousDimensions.size(); ++j) {
+ startOffset *= previousDimensions[j];
+ }
+ if (previousDimensions.size() == 0) {
+ startOffset = 0;
+ }
+ containedInPriorDimensions += startOffset;
+ int dimensionTotal = 1;
+ for (unsigned int j = 0; j < dimensions.size(); ++j) {
+ dimensionTotal *= dimensions[j];
+ }
+ if (containedInDimensions > 0) {
+ void * partialArray = NULL;
+ if (array.getArrayType() == XdmfArrayType::Int8()) {
+ partialArray =
+ &(((char *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Int16()) {
+ partialArray =
+ &(((short *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Int32()) {
+ partialArray =
+ &(((int *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Int64()) {
+ partialArray =
+ &(((long *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Float32()) {
+ partialArray =
+ &(((float *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Float64()) {
+ partialArray =
+ &(((double *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::UInt8()) {
+ partialArray =
+ &(((unsigned char *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::UInt16()) {
+ partialArray =
+ &(((unsigned short *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::UInt32()) {
+ partialArray =
+ &(((unsigned int *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::String()) {
+ partialArray =
+ &(((std::string *)array.getValuesInternal())[containedInPriorDimensions]);
+ }
+ arraysWritten.push_back(partialArray);
+ filesWritten.push_back(testFile.str());
+ datasetsWritten.push_back(dataSetPath);
+ datasetIdsWritten.push_back(dataSetId);
+ startsWritten.push_back(partialStarts);
+ stridesWritten.push_back(partialStrides);
+ dimensionsWritten.push_back(partialDimensions);
+ dataSizesWritten.push_back(partialDataSizes);
+ arrayOffsetsWritten.push_back(containedInPriorDimensions);
+ }
+ if (mMode == Hyperslab) {
+ containedInPriorDimensions -= controllerIndexOffset;
+ }
+ if (containedInDimensions + containedInPriorDimensions == dimensionTotal) {
+ controllerIndexOffset += dimensionTotal;
+ }
+ // For hyperslab the space is controlled by the dataspace dimensions
+ // So use that since the dimensions should be equal
+ // to the dataspace dimensions in all other variations
+ // Total up written data space
+ unsigned int writtenDataSpace = 1;
+ for (unsigned int j = 0; j < partialDataSizes.size(); ++j) {
+ writtenDataSpace *= partialDataSizes[j];
+ }
+ amountAlreadyWritten += writtenDataSpace;
+ // Generate previous dimensions
+ if (previousDataSizes.size() == 0) {
+ previousDataSizes = partialDataSizes;
+ previousDimensions = partialDimensions;
+ }
+ else {
+ // Determine if the sizes match
+ // If they do, add the top values together
+ // Otherwise, compress the higher dimensions and then add them
+ if (previousDimensions.size() == partialDimensions.size()) {
+ previousDimensions[previousDimensions.size()-1] +=
+ partialDimensions[previousDimensions.size()-1];
+ }
+ else if (previousDimensions.size() < partialDimensions.size()) {
+ unsigned int overflowDimensions = 1;
+ for (unsigned int j = previousDimensions.size() - 1;
+ j < partialDimensions.size();
+ ++j) {
+ overflowDimensions *= partialDimensions[j];
+ }
+ previousDimensions[previousDimensions.size()-1] += overflowDimensions;
+ }
+ else if (previousDimensions.size() > partialDimensions.size()) {
+ unsigned int overflowDimensions = 1;
+ for (unsigned int j = partialDimensions.size() - 1;
+ j < previousDimensions.size();
+ ++j) {
+ overflowDimensions *= previousDimensions[j];
+ }
+ previousDimensions.resize(partialDimensions.size());
+ previousDimensions[partialDimensions.size()-1] = overflowDimensions;
+ previousDimensions[previousDimensions.size()-1] +=
+ partialDimensions[previousDimensions.size()-1];
+ }
+ if (previousDataSizes.size() == partialDataSizes.size()) {
+ previousDataSizes[previousDataSizes.size()-1] +=
+ partialDataSizes[previousDataSizes.size()-1];
+ }
+ else if (previousDataSizes.size() < partialDataSizes.size()) {
+ unsigned int overflowDataSizes = 1;
+ for (unsigned int j = previousDataSizes.size() - 1;
+ j < partialDataSizes.size();
+ ++j) {
+ overflowDataSizes *= partialDataSizes[j];
+ }
+ previousDataSizes[previousDataSizes.size()-1] += overflowDataSizes;
+ }
+ else if (previousDataSizes.size() > partialDataSizes.size()) {
+ unsigned int overflowDataSizes = 1;
+ for (unsigned int j = partialDataSizes.size() - 1;
+ j < previousDataSizes.size();
+ ++j) {
+ overflowDataSizes *= previousDataSizes[j];
+ }
+ previousDataSizes.resize(partialDataSizes.size());
+ previousDataSizes[partialDataSizes.size()-1] = overflowDataSizes;
+ previousDataSizes[previousDataSizes.size()-1] +=
+ partialDataSizes[previousDataSizes.size()-1];
+ }
+ }
+ }
+ ++dataSetId;
+ }
+
+ if (mMode == Append) {
+ // If the written filename is different write add the previous controller
+ if (*(filesWritten.rbegin()) != heavyDataController->getFilePath()) {
+ // Should also be different from previous controller
+ if (filesWritten.size() > 1) {
+ if (*(filesWritten.rbegin()) != *((filesWritten.rbegin())++)) {
+ array.insert(heavyDataController);
+ }
+ }
+ else {
+ array.insert(heavyDataController);
+ }
+ }
+ }
+ }
+ else {
+ // Otherwise work with the full array
+ void * partialArray = NULL;
+ // Need to copy by duplicating the contents of the array
+ unsigned int j = controllerIndexOffset;
+ std::string writtenFileName = "";
+ if (mMode == Default) {
+ std::stringstream testFile;
+ if (getFileIndex() == 0) {
+ // If sequentially named files need to be created or referenced
+ testFile << checkFileName << "." << checkFileExt;
+ }
+ else {
+ testFile << checkFileName << getFileIndex() << "." << checkFileExt;
+ }
+ writtenFileName = testFile.str();
+ }
+ else {
+ writtenFileName = heavyDataController->getFilePath();
+ }
+
+ if (array.getArrayType() == XdmfArrayType::Int8()){
+ partialArray =
+ &(((char *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Int16()){
+ partialArray =
+ &(((short *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Int32()){
+ partialArray =
+ &(((int *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Int64()){
+ partialArray =
+ &(((long *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Float32()){
+ partialArray =
+ &(((float *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::Float64()){
+ partialArray =
+ &(((double *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::UInt8()){
+ partialArray =
+ &(((unsigned char *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::UInt16()){
+ partialArray =
+ &(((unsigned short *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::UInt32()) {
+ partialArray =
+ &(((unsigned int *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ else if (array.getArrayType() == XdmfArrayType::String()) {
+ partialArray =
+ &(((std::string *)array.getValuesInternal())[controllerIndexOffset]);
+ }
+ arrayOffsetsWritten.push_back(controllerIndexOffset);
+ // Set the offset to the point after the end of the current subset
+ controllerIndexOffset = j;
+
+ arraysWritten.push_back(partialArray);
+ filesWritten.push_back(writtenFileName);
+ datasetsWritten.push_back(dataSetPath);
+ datasetIdsWritten.push_back(dataSetId);
+ // Also need to push the starts and strides loaded from the HeavyDataController
+ startsWritten.push_back(start);
+ stridesWritten.push_back(stride);
+ dimensionsWritten.push_back(dimensions);
+ dataSizesWritten.push_back(dataspaceDimensions);
+ }
+}
+
+shared_ptr<XdmfHeavyDataController>
+XdmfHDF5Writer::createController(const std::string & hdf5FilePath,
+ const std::string & dataSetPath,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions)
+{
+ return XdmfHDF5Controller::New(hdf5FilePath,
+ dataSetPath,
+ type,
+ start,
+ stride,
+ dimensions,
+ dataspaceDimensions);
+}
+
+unsigned int
+XdmfHDF5Writer::getChunkSize() const
+{
+ return mImpl->mChunkSize;
+}
+
+int
+XdmfHDF5Writer::getDataSetSize(shared_ptr<XdmfHeavyDataController> descriptionController)
+{
+ return getDataSetSize(descriptionController->getFilePath(),
+ shared_dynamic_cast<XdmfHDF5Controller>(descriptionController)->getDataSetPath());
+}
+
+int
+XdmfHDF5Writer::getDataSetSize(const std::string & fileName, const std::string & dataSetName)
+{
+ hid_t handle = -1;
+ H5E_auto_t old_func;
+ void * old_client_data;
+ H5Eget_auto(0, &old_func, &old_client_data);
+ H5Eset_auto2(0, NULL, NULL);
+ if (XdmfSystemUtils::getRealPath(fileName) != mImpl->mOpenFile) {
+ // Save old error handler and turn off error handling for now
+
+ if(H5Fis_hdf5(fileName.c_str()) > 0) {
+ handle = H5Fopen(fileName.c_str(),
+ H5F_ACC_RDWR,
+ mImpl->mFapl);
+ }
+ else {
+ // This is where it currently fails
+ handle = H5Fcreate(fileName.c_str(),
+ H5F_ACC_TRUNC,
+ H5P_DEFAULT,
+ mImpl->mFapl);
+ }
+ }
+ else {
+ handle = mImpl->mHDF5Handle;
+ }
+
+ // Restore previous error handler
+ H5Eset_auto2(0, old_func, old_client_data);
+
+ if (!H5Lexists(mImpl->mHDF5Handle,
+ dataSetName.c_str(),
+ H5P_DEFAULT))
+ {
+ return 0;
+ }
+
+ hid_t checkset = H5Dopen(handle,
+ dataSetName.c_str(),
+ H5P_DEFAULT);
+ hid_t checkspace = H5S_ALL;
+ checkspace = H5Dget_space(checkset);
+ hssize_t checksize = H5Sget_simple_extent_npoints(checkspace);
+ herr_t status = H5Dclose(checkset);
+ if(checkspace != H5S_ALL) {
+ status = H5Sclose(checkspace);
+ }
+ if (handle != mImpl->mHDF5Handle) {
+ H5Fclose(handle);
+ }
+ return checksize;
+}
+
+int
+XdmfHDF5Writer::getDeflateFactor() const
+{
+ return mDeflateFactor;
+}
+
+bool
+XdmfHDF5Writer::getUseDeflate() const
+{
+ return mUseDeflate;
+}
+
+void
+XdmfHDF5Writer::closeFile()
+{
+ mImpl->closeFile();
+}
+
+void
+XdmfHDF5Writer::openFile()
+{
+ mDataSetId = mImpl->openFile(mFilePath,
+ mDataSetId);
+}
+
+void
+XdmfHDF5Writer::setChunkSize(const unsigned int chunkSize)
+{
+ mImpl->mChunkSize = chunkSize;
+}
+
+void
+XdmfHDF5Writer::setDeflateFactor(int factor)
+{
+ mDeflateFactor = factor;
+}
+
+void
+XdmfHDF5Writer::setUseDeflate(bool status)
+{
+ mUseDeflate = status;
+}
+
+void
+XdmfHDF5Writer::visit(XdmfArray & array,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ mImpl->mDepth++;
+ std::set<const XdmfItem *>::iterator checkWritten = mImpl->mWrittenItems.find(&array);
+ if (checkWritten == mImpl->mWrittenItems.end()) {
+ // If it has children send the writer to them too.
+ array.traverse(visitor);
+ if (array.isInitialized() && array.getSize() > 0) {
+ // Only do this if the object has not already been written
+ this->write(array);
+ mImpl->mWrittenItems.insert(&array);
+ }
+ }
+ // If the object has already been written, just end, it already has the data
+ mImpl->mDepth--;
+ if(mImpl->mDepth <= 0) {
+ mImpl->mWrittenItems.clear();
+ }
+}
+
+
+void
+XdmfHDF5Writer::visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ mImpl->mDepth++;
+ // This is similar to the algorithm for writing XPaths
+ // shouldn't be a problem if XPaths are turned off because all this does is avoid writing an object twice
+ // if it was written once then all instances of the object should have the controller
+ std::set<const XdmfItem *>::iterator checkWritten = mImpl->mWrittenItems.find(&item);
+ if (checkWritten == mImpl->mWrittenItems.end()) {
+ mImpl->mWrittenItems.insert(&item);
+ item.traverse(visitor);
+ }
+ mImpl->mDepth--;
+ if(mImpl->mDepth <= 0) {
+ mImpl->mWrittenItems.clear();
+ }
+}
+
+
+void
+XdmfHDF5Writer::write(XdmfArray & array)
+{
+ hid_t datatype = -1;
+ bool closeDatatype = false;
+
+ // Determining data type
+ if(array.isInitialized()) {
+ if(array.getArrayType() == XdmfArrayType::Int8()) {
+ datatype = H5T_NATIVE_CHAR;
+ }
+ else if(array.getArrayType() == XdmfArrayType::Int16()) {
+ datatype = H5T_NATIVE_SHORT;
+ }
+ else if(array.getArrayType() == XdmfArrayType::Int32()) {
+ datatype = H5T_NATIVE_INT;
+ }
+ else if(array.getArrayType() == XdmfArrayType::Int64()) {
+ datatype = H5T_NATIVE_LONG;
+ }
+ else if(array.getArrayType() == XdmfArrayType::Float32()) {
+ datatype = H5T_NATIVE_FLOAT;
+ }
+ else if(array.getArrayType() == XdmfArrayType::Float64()) {
+ datatype = H5T_NATIVE_DOUBLE;
+ }
+ else if(array.getArrayType() == XdmfArrayType::UInt8()) {
+ datatype = H5T_NATIVE_UCHAR;
+ }
+ else if(array.getArrayType() == XdmfArrayType::UInt16()) {
+ datatype = H5T_NATIVE_USHORT;
+ }
+ else if(array.getArrayType() == XdmfArrayType::UInt32()) {
+ datatype = H5T_NATIVE_UINT;
+ }
+ else if(array.getArrayType() == XdmfArrayType::String()) {
+ // Strings are a special case as they have mutable size
+ datatype = H5Tcopy(H5T_C_S1);
+ H5Tset_size(datatype, H5T_VARIABLE);
+ closeDatatype = true;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Array of unsupported type in "
+ "XdmfHDF5Writer::write");
+ }
+ }
+
+ herr_t status;
+
+ if(datatype != -1) {
+ std::string hdf5FilePath = mFilePath;
+
+ size_t extIndex;
+ std::string checkFileName;
+ std::string checkFileExt;
+ extIndex = hdf5FilePath.find_last_of(".");
+ if (extIndex == std::string::npos) {
+ checkFileName = hdf5FilePath;
+ checkFileExt = "";
+ }
+ else {
+ checkFileName = hdf5FilePath.substr(0, extIndex);
+ checkFileExt = hdf5FilePath.substr(extIndex+1);
+ }
+
+ std::stringstream dataSetPath;
+
+ std::vector<shared_ptr<XdmfHeavyDataController> > previousControllers;
+
+ // Hold the controllers in order to base the new controllers on them
+ for(unsigned int i = 0; i < array.getNumberHeavyDataControllers(); ++i) {
+ // discard controllers of the wrong type
+ if (shared_ptr<XdmfHDF5Controller> controller =
+ shared_dynamic_cast<XdmfHDF5Controller>(array.getHeavyDataController(i)) )
+ {
+ previousControllers.push_back(array.getHeavyDataController(i));
+ }
+ }
+
+ // Remove controllers from the array
+ // they will be replaced by the controllers created by this function.
+ while(array.getNumberHeavyDataControllers() != 0) {
+ array.removeHeavyDataController(array.getNumberHeavyDataControllers() -1);
+ }
+
+ bool hasControllers = true;
+
+ if (previousControllers.size() == 0) {
+ // Create a temporary controller if the array doesn't have one
+ hasControllers = false;
+ shared_ptr<XdmfHeavyDataController> tempDataController =
+ this->createController(hdf5FilePath,
+ "Data",
+ array.getArrayType(),
+ std::vector<unsigned int>(1, 0),
+ std::vector<unsigned int>(1, 1),
+ std::vector<unsigned int>(1, array.getSize()),
+ std::vector<unsigned int>(1, array.getSize()));
+ previousControllers.push_back(tempDataController);
+ }
+
+ int controllerIndexOffset = 0;
+
+ // It is assumed that the array will have at least one controller
+ // if it didn't have one a temporary one was generated
+ for(unsigned int i = 0; i < previousControllers.size(); ++i)
+ {
+ if (mMode == Append) {
+ // Append only cares about the last controller, so add the rest back in
+ for (; i < previousControllers.size() - 1; ++i) {
+ array.insert(previousControllers[i]);
+ }
+ }
+
+ std::list<std::string> filesWritten;
+ std::list<std::string> datasetsWritten;
+ std::list<int> datasetIdsWritten;
+ std::list<void *> arraysWritten;
+ std::list<std::vector<unsigned int> > startsWritten;
+ std::list<std::vector<unsigned int> > stridesWritten;
+ std::list<std::vector<unsigned int> > dimensionsWritten;
+ std::list<std::vector<unsigned int> > dataSizesWritten;
+ std::list<unsigned int> arrayOffsetsWritten;
+
+ // Open a hdf5 dataset and write to it on disk.
+ hsize_t size = array.getSize();
+
+ // Save old error handler and turn off error handling for now
+ H5E_auto_t old_func;
+ void * old_client_data;
+ H5Eget_auto(0, &old_func, &old_client_data);
+ H5Eset_auto2(0, NULL, NULL);
+
+ // If this is in hyperslab mode, this loop will need to execute multiple times
+ // Otherwise the boolean is used simply to start it and one pass is made
+ bool startedloop = false;
+ unsigned int origFileIndex = getFileIndex();
+ while ((mMode == Hyperslab
+ && i < previousControllers.size())
+ || !startedloop) {
+ // Hyperslab mode wants to assign all data using the current location
+ // without writing until all data sets are determined
+
+ startedloop = true;
+
+ shared_ptr<XdmfHDF5Controller> heavyDataController =
+ shared_dynamic_cast<XdmfHDF5Controller>(previousControllers[i]);
+ // Stats for the data currently stored in the array
+
+ std::vector<unsigned int> dimensions;
+ if (mMode != Hyperslab) {
+ dimensions = array.getDimensions();
+ }
+ else {
+ dimensions = heavyDataController->getDimensions();
+ }
+ std::vector<unsigned int> dataspaceDimensions = dimensions;
+ std::vector<unsigned int> start(dimensions.size(), 0);
+ std::vector<unsigned int> stride(dimensions.size(), 1);
+
+ if((mMode == Overwrite || mMode == Append || mMode == Hyperslab)
+ && heavyDataController) {
+
+ // Write to the previous dataset
+ dataSetPath.str(std::string());
+ dataSetPath << heavyDataController->getDataSetPath();
+ hdf5FilePath = heavyDataController->getFilePath();
+ if(mMode == Hyperslab) {
+ // Start, stride, and dataspace dimensions only matter for hyperslab mode
+ dataspaceDimensions = heavyDataController->getDataspaceDimensions();
+ start = heavyDataController->getStart();
+ stride = heavyDataController->getStride();
+ }
+ }
+ else {
+ dataSetPath.str(std::string());
+ dataSetPath << "Data" << mDataSetId;
+ }
+
+ // Check here for if the file would become
+ // larger than the limit after the addition.
+ // Then check subsequent files for the same limitation
+ std::string passPath = dataSetPath.str();
+ controllerSplitting(array,
+ controllerIndexOffset,
+ heavyDataController,
+ checkFileName,
+ checkFileExt,
+ heavyDataController->getDataSetPrefix(),
+ heavyDataController->getDataSetId(),
+ dimensions,
+ dataspaceDimensions,
+ start,
+ stride,
+ filesWritten,
+ datasetsWritten,
+ datasetIdsWritten,
+ arraysWritten,
+ startsWritten,
+ stridesWritten,
+ dimensionsWritten,
+ dataSizesWritten,
+ arrayOffsetsWritten);
+
+ if (mMode == Hyperslab)
+ {
+ // In hyperslab mode, reset the file index and move to next iteration
+ i++;
+ setFileIndex(origFileIndex);
+ }
+
+ }
+
+ std::list<std::string>::iterator fileNameWalker = filesWritten.begin();
+ std::list<std::string>::iterator datasetWalker = datasetsWritten.begin();
+ std::list<int>::iterator datasetIdWalker = datasetIdsWritten.begin();
+ std::list<void *>::iterator arrayWalker = arraysWritten.begin();
+ std::list<std::vector<unsigned int> >::iterator startWalker = startsWritten.begin();
+ std::list<std::vector<unsigned int> >::iterator strideWalker = stridesWritten.begin();
+ std::list<std::vector<unsigned int> >::iterator dimensionWalker = dimensionsWritten.begin();
+ std::list<std::vector<unsigned int> >::iterator dataSizeWalker = dataSizesWritten.begin();
+ std::list<unsigned int>::iterator arrayOffsetWalker = arrayOffsetsWritten.begin();
+
+ // Loop based on the amount of blocks split from the array.
+ for (unsigned int writeIndex = 0; writeIndex < arraysWritten.size(); ++writeIndex) {
+ // This is the section where the data is written to hdf5
+ // If you want to change the writer to write to a different data format, do it here
+
+ std::string curFileName = *fileNameWalker;
+ std::string currDataset = *datasetWalker;
+ int currDatasetId = *datasetIdWalker;
+ void * curArray = *arrayWalker;
+ std::vector<unsigned int> curStart = *startWalker;
+ std::vector<unsigned int> curStride = *strideWalker;
+ std::vector<unsigned int> curDimensions = *dimensionWalker;
+ std::vector<unsigned int> curDataSize = *dataSizeWalker;
+ unsigned int curArrayOffset = *arrayOffsetWalker;
+
+
+ bool closeFile = false;
+ // This is meant to open files if it isn't already opened by the write prior
+ // If it wasn't open prior to writing it will be closed after writing
+ if (mImpl->mOpenFile.compare(curFileName) != 0) {
+ if(mImpl->mHDF5Handle < 0) {
+ closeFile = true;
+ }
+ mImpl->openFile(curFileName,
+ mDataSetId);
+ }
+
+ if (currDatasetId >= 0)
+ {
+ mDataSetId = currDatasetId;
+ dataSetPath.str(std::string());
+ dataSetPath << currDataset << mDataSetId;
+ }
+
+ htri_t testingSet = H5Lexists(mImpl->mHDF5Handle,
+ dataSetPath.str().c_str(),
+ H5P_DEFAULT);
+
+ hid_t dataset = 0;
+
+ if (testingSet == 0) {
+ dataset = -1;
+ }
+ else {
+ dataset = H5Dopen(mImpl->mHDF5Handle,
+ dataSetPath.str().c_str(),
+ H5P_DEFAULT);
+ }
+
+ // If default mode find a new data set to write to (keep
+ // incrementing dataSetId)
+ if(dataset >=0 &&
+ (mMode == Default ||
+ (mMode == Hyperslab && !hasControllers))) {
+ while(true) {
+ dataSetPath.str(std::string());
+ dataSetPath << currDataset << ++mDataSetId;
+ if(!H5Lexists(mImpl->mHDF5Handle,
+ dataSetPath.str().c_str(),
+ H5P_DEFAULT)) {
+ //Close previous dataset
+ status = H5Dclose(dataset);
+ dataset = H5Dopen(mImpl->mHDF5Handle,
+ dataSetPath.str().c_str(),
+ H5P_DEFAULT);
+ break;
+ }
+ }
+ }
+
+ // Restore previous error handler
+ H5Eset_auto2(0, old_func, old_client_data);
+
+ hid_t dataspace = H5S_ALL;
+ hid_t memspace = H5S_ALL;
+
+ std::vector<hsize_t> current_dims(curDataSize.begin(),
+ curDataSize.end());
+
+ if(dataset < 0) {
+ // If the dataset doesn't contain anything
+
+ std::vector<hsize_t> maximum_dims(curDimensions.size(), H5S_UNLIMITED);
+ // Create a new dataspace
+ dataspace = H5Screate_simple(current_dims.size(),
+ ¤t_dims[0],
+ &maximum_dims[0]);
+ hid_t property = H5Pcreate(H5P_DATASET_CREATE);
+
+ const hsize_t totalDimensionsSize =
+ std::accumulate(current_dims.begin(),
+ current_dims.end(),
+ (hsize_t) 1,
+ std::multiplies<hsize_t>());
+ // The Nth root of the chunk size divided by the dimensions added together
+ const double factor =
+ std::pow(((double)mImpl->mChunkSize / totalDimensionsSize),
+ 1.0 / current_dims.size());
+ // The end result is the amount of slots alloted per unit of dimension
+ std::vector<hsize_t> chunk_size(current_dims.begin(),
+ current_dims.end());
+ if (mImpl->mChunkSize > 0) {
+ // The chunk size won't do anything unless it's positive
+ for(std::vector<hsize_t>::iterator iter = chunk_size.begin();
+ iter != chunk_size.end(); ++iter) {
+ *iter = (hsize_t)(*iter * factor);
+ if(*iter == 0) {
+ *iter = 1;
+ }
+ }
+ }
+
+ // Set ZLIB / DEFLATE Compression
+ if (mUseDeflate)
+ {
+ status = H5Pset_deflate(property, mDeflateFactor);
+ }
+
+ status = H5Pset_chunk(property, current_dims.size(), &chunk_size[0]);
+ // Use that dataspace to create a new dataset
+ dataset = H5Dcreate(mImpl->mHDF5Handle,
+ dataSetPath.str().c_str(),
+ datatype,
+ dataspace,
+ H5P_DEFAULT,
+ property,
+ H5P_DEFAULT);
+ status = H5Pclose(property);
+ }
+
+ if(mMode == Append) {
+ // Need to resize dataset to fit new data
+
+ // Get size of old dataset
+ dataspace = H5Dget_space(dataset);
+ hssize_t datasize = H5Sget_simple_extent_npoints(dataspace);
+ status = H5Sclose(dataspace);
+
+ // Reset the datasize if the file or set is different
+ if (curFileName != previousControllers[i]->getFilePath()) {
+ datasize = 0;
+ }
+ if (shared_ptr<XdmfHDF5Controller> setPathController =
+ shared_dynamic_cast<XdmfHDF5Controller>(previousControllers[i])) {
+ if (dataSetPath.str() != setPathController->getDataSetPath()) {
+ datasize = 0;
+ }
+ }
+ else {
+ datasize = 0;
+ }
+
+ unsigned int sizeTotal = 1;
+
+ for (unsigned int dataSizeIter = 0; dataSizeIter < curDataSize.size(); ++dataSizeIter) {
+ sizeTotal = sizeTotal * curDataSize[dataSizeIter];
+ }
+
+ // Resize to fit size of old and new data.
+ hsize_t newSize = sizeTotal + datasize;
+ status = H5Dset_extent(dataset, &newSize);
+
+ // Select hyperslab to write to.
+ memspace = H5Screate_simple(1, &size, NULL);
+ dataspace = H5Dget_space(dataset);
+ hsize_t dataStart = datasize;
+ status = H5Sselect_hyperslab(dataspace,
+ H5S_SELECT_SET,
+ &dataStart,
+ NULL,
+ &size,
+ NULL);
+ }
+ else if(mMode == Overwrite) {
+ // Overwriting - dataset rank must remain the same (hdf5 constraint)
+ dataspace = H5Dget_space(dataset);
+
+ const unsigned int ndims = H5Sget_simple_extent_ndims(dataspace);
+ if(ndims != current_dims.size()) {
+ XdmfError::message(XdmfError::FATAL, \
+ "Data set rank different -- ndims != "
+ "current_dims.size() -- in "
+ "XdmfHDF5Writer::write");
+ }
+
+ status = H5Dset_extent(dataset, ¤t_dims[0]);
+ dataspace = H5Dget_space(dataset);
+ }
+ else if(mMode == Hyperslab) {
+ // Hyperslab - dataset rank must remain the same (hdf5 constraint)
+ dataspace = H5Dget_space(dataset);
+
+ const unsigned int ndims = H5Sget_simple_extent_ndims(dataspace);
+ if(ndims != current_dims.size()) {
+ XdmfError::message(XdmfError::FATAL, \
+ "Data set rank different -- ndims != "
+ "current_dims.size() -- in "
+ "XdmfHDF5Writer::write");
+ }
+ status = H5Dset_extent(dataset, ¤t_dims[0]);
+ dataspace = H5Dget_space(dataset);
+
+
+
+
+ std::vector<hsize_t> count(curDimensions.begin(),
+ curDimensions.end());
+ std::vector<hsize_t> currStride(curStride.begin(),
+ curStride.end());
+ std::vector<hsize_t> currStart(curStart.begin(),
+ curStart.end());
+
+ memspace = H5Screate_simple(count.size(),
+ &(count[0]),
+ NULL);
+ status = H5Sselect_hyperslab(dataspace,
+ H5S_SELECT_SET,
+ &currStart[0],
+ &currStride[0],
+ &count[0],
+ NULL) ;
+
+ if(status < 0) {
+ std::stringstream sstr;
+ sstr << "H5Dset_extent returned failure in "
+ "XdmfHDF5Writer::write -- status: " << status;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+ }
+
+ status = H5Dwrite(dataset,
+ datatype,
+ memspace,
+ dataspace,
+ H5P_DEFAULT,
+ curArray);
+
+ if(status < 0) {
+ std::stringstream sstr;
+ sstr << "H5Dwrite returned failure in XdmfHDF5Writer::write "
+ "-- status: " << status;
+ XdmfError::message(XdmfError::FATAL, sstr.str());
+ }
+
+ if(dataspace != H5S_ALL) {
+ status = H5Sclose(dataspace);
+ }
+
+ if(memspace != H5S_ALL) {
+ status = H5Sclose(memspace);
+ }
+
+ status = H5Dclose(dataset);
+
+ H5Fflush(mImpl->mHDF5Handle, H5F_SCOPE_GLOBAL);
+
+ // This is causing a lot of overhead
+ if(closeFile) {
+ mImpl->closeFile();
+ }
+
+ // Attach a new controller to the array
+ shared_ptr<XdmfHDF5Controller> newDataController =
+ shared_ptr<XdmfHDF5Controller>();
+ //This generates an empty pointer
+
+ unsigned int newSize;
+ if(mMode == Append) {
+ // Find data size
+ mImpl->openFile(curFileName,
+ mDataSetId);
+ hid_t checkset = H5Dopen(mImpl->mHDF5Handle,
+ dataSetPath.str().c_str(),
+ H5P_DEFAULT);
+ hid_t checkspace = H5S_ALL;
+ checkspace = H5Dget_space(checkset);
+ newSize = H5Sget_simple_extent_npoints(checkspace);
+ status = H5Dclose(checkset);
+ if(checkspace != H5S_ALL) {
+ status = H5Sclose(checkspace);
+ }
+
+ std::vector<unsigned int> insertStarts;
+ insertStarts.push_back(0);
+ std::vector<unsigned int> insertStrides;
+ insertStrides.push_back(1);
+ std::vector<unsigned int> insertDimensions;
+ insertDimensions.push_back(newSize);
+ std::vector<unsigned int> insertDataSpaceDimensions;
+ insertDataSpaceDimensions.push_back(newSize);
+
+ newDataController =
+ shared_dynamic_cast<XdmfHDF5Controller>(this->createController(curFileName,
+ dataSetPath.str(),
+ array.getArrayType(),
+ insertStarts,
+ insertStrides,
+ insertDimensions,
+ insertDataSpaceDimensions));
+ }
+
+ if(!newDataController) {
+ // If the controller wasn't generated by append
+ newDataController =
+ shared_dynamic_cast<XdmfHDF5Controller>(this->createController(curFileName,
+ dataSetPath.str(),
+ array.getArrayType(),
+ curStart,
+ curStride,
+ curDimensions,
+ curDataSize));
+ }
+
+ newDataController->setArrayOffset(curArrayOffset);
+
+ array.insert(newDataController);
+
+ fileNameWalker++;
+ datasetWalker++;
+ datasetIdWalker++;
+ arrayWalker++;
+ startWalker++;
+ strideWalker++;
+ dimensionWalker++;
+ dataSizeWalker++;
+ arrayOffsetWalker++;
+
+ if (mMode == Default) {
+ dataSetPath.str(std::string());
+ dataSetPath << "Data" << ++mDataSetId;
+ }
+
+ }
+
+ }
+
+ if(closeDatatype) {
+ status = H5Tclose(datatype);
+ }
+
+ if(mReleaseData) {
+ array.release();
+ }
+ }
+}
+
+// C Wrappers
+
+XDMFHDF5WRITER * XdmfHDF5WriterNew(char * fileName, int clobberFile)
+{
+ try
+ {
+ shared_ptr<XdmfHDF5Writer> generatedWriter = XdmfHDF5Writer::New(std::string(fileName), clobberFile);
+ return (XDMFHDF5WRITER *)((void *)(new XdmfHDF5Writer(*generatedWriter.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfHDF5Writer> generatedWriter = XdmfHDF5Writer::New(std::string(fileName), clobberFile);
+ return (XDMFHDF5WRITER *)((void *)(new XdmfHDF5Writer(*generatedWriter.get())));
+ }
+}
+
+void XdmfHDF5WriterCloseFile(XDMFHDF5WRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfHDF5Writer *)writer)->closeFile();
+ XDMF_ERROR_WRAP_END(status)
+}
+
+unsigned int XdmfHDF5WriterGetChunkSize(XDMFHDF5WRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return ((XdmfHDF5Writer *)writer)->getChunkSize();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+void XdmfHDF5WriterOpenFile(XDMFHDF5WRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfHDF5Writer *)writer)->openFile();
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfHDF5WriterSetChunkSize(XDMFHDF5WRITER * writer, unsigned int chunkSize, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfHDF5Writer *)writer)->setChunkSize(chunkSize);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_HEAVYWRITER_C_CHILD_WRAPPER(XdmfHDF5Writer, XDMFHDF5WRITER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHDF5Writer.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFHDF5WRITER_HPP_
+#define XDMFHDF5WRITER_HPP_
+
+// C Compatible includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+#include "XdmfHeavyDataController.hpp"
+
+#include "vtk_hdf5.h"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+class XdmfArrayType;
+class XdmfHDF5Controller;
+
+// Includes
+#include <list>
+#include <set>
+
+/**
+ * @brief Traverse the Xdmf graph and write heavy data stored in
+ * XdmfArrays to HDF5 on disk.
+ *
+ * XdmfHDF5Writer traverses an Xdmf graph structure and writes data
+ * stored in XdmfArrays to HDF5. Writing begins by calling the
+ * accept() operation on any XdmfItem and supplying this writer as the
+ * parameter. The writer will write all XdmfArrays under the XdmfItem
+ * to an hdf5 file on disk. It will also attach an XdmfHDF5Controller
+ * to all XdmfArrays that it writes to disk.
+ *
+ * This writer supports all heavy data writing modes listed in
+ * XdmfHeavyDataWriter.
+ */
+class XDMFCORE_EXPORT XdmfHDF5Writer : public XdmfHeavyDataWriter {
+
+public:
+
+ /**
+ * Construct XdmfHDF5Writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param filePath The location of the hdf5 file to output to on disk.
+ * @param clobberFile Whether to overwrite the previous file if it exists.
+ *
+ * @return New XdmfHDF5Writer.
+ */
+ static shared_ptr<XdmfHDF5Writer> New(const std::string & filePath,
+ const bool clobberFile = false);
+
+ virtual ~XdmfHDF5Writer();
+
+
+ virtual void closeFile();
+
+ /**
+ * Get the chunk size used to output datasets to hdf5.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getChunkSize
+ * @until //#getChunkSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getChunkSize
+ * @until #//getChunkSize
+ *
+ * @return Chunk size used to output datasets to hdf5.
+ */
+ unsigned int getChunkSize() const;
+
+ virtual int getDataSetSize(const std::string & fileName,
+ const std::string & dataSetName);
+
+ /**
+ * Gets the factor that Deflate uses to compress data.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDeflateFactor
+ * @until //#getDeflateFactor
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDeflateFactor
+ * @until #//getDeflateFactor
+ *
+ * @return The factor Deflate uses.
+ */
+ int getDeflateFactor() const;
+
+ /**
+ * Gets whether Deflate is enabled.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getUseDeflate
+ * @until //#getUseDeflate
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getUseDeflate
+ * @until #//getUseDeflate
+ *
+ * @return Whether Deflate is in use.
+ */
+ bool getUseDeflate() const;
+
+ virtual void openFile();
+
+ /**
+ * Set the chunk size used to output datasets to hdf5. For
+ * multidimensional datasets the chunk size is the total number of
+ * elements in the chunk.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setChunkSize
+ * @until //#setChunkSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setChunkSize
+ * @until #//setChunkSize
+ *
+ * @param chunkSize The number of elements per chunk.
+ */
+ void setChunkSize(const unsigned int chunkSize);
+
+ /**
+ * Sets the factor that Deflate will use to compress data.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setDeflateFactor
+ * @until //#setDeflateFactor
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setDeflateFactor
+ * @until #//setDeflateFactor
+ *
+ * @param factor The factor Deflate will use.
+ */
+ void setDeflateFactor(int factor);
+
+ /**
+ * Sets whether HDF5 will use Deflate compression
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Writer.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setUseDeflate
+ * @until //#setUseDeflate
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Writer.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setUseDeflate
+ * @until #//setUseDeflate
+ *
+ * @param status Whether Deflate will be used.
+ */
+ void setUseDeflate(bool status);
+
+ using XdmfHeavyDataWriter::visit;
+ virtual void visit(XdmfArray & array,
+ const shared_ptr<XdmfBaseVisitor> visitor);
+
+ virtual void visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfHDF5Writer(const XdmfHDF5Writer &);
+
+protected:
+
+ XdmfHDF5Writer(const std::string & filePath);
+
+ /**
+ * Create a new HDF5 Controller that is able to read in after being
+ * written by this writer.
+ *
+ * @param hdf5FilePath the location of the hdf5 file the data set resides in.
+ * @param dataSetPath the location of the dataset within the hdf5 file.
+ * @param type the data type of the dataset to read.
+ * @param start the offset of the starting element in each dimension in
+ * the hdf5 data set.
+ * @param stride the number of elements to move in each dimension from the
+ * hdf5 data set.
+ * @param dimensions the number of elements to select in each
+ * dimension from the hdf5 data set. (size in each dimension)
+ * @param dataspaceDimensions the number of elements in the entire
+ * hdf5 data set (may be larger that dimensions if using
+ * hyperslabs).
+ *
+ * @return new HDF5 Controller.
+ */
+ virtual shared_ptr<XdmfHeavyDataController>
+ createController(const std::string & hdf5FilePath,
+ const std::string & descriptor,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions);
+
+ virtual int getDataSetSize(shared_ptr<XdmfHeavyDataController> descriptionController);
+
+ /**
+ * Write the XdmfArray to a hdf5 file.
+ *
+ * @param array An XdmfArray to write to hdf5.
+ */
+ virtual void write(XdmfArray & array);
+
+ /**
+ * PIMPL
+ */
+ class XdmfHDF5WriterImpl
+ {
+ public:
+
+ XdmfHDF5WriterImpl();
+
+ virtual ~XdmfHDF5WriterImpl();
+
+ virtual void
+ closeFile();
+
+ virtual int
+ openFile(const std::string & filePath,
+ const int mDataSetId);
+
+ hid_t mHDF5Handle;
+ int mFapl;
+ unsigned int mChunkSize;
+ std::string mOpenFile;
+ int mDepth;
+ std::set<const XdmfItem *> mWrittenItems;
+ };
+
+ XdmfHDF5WriterImpl * mImpl;
+
+ bool mUseDeflate;
+ int mDeflateFactor;
+
+private:
+
+ void operator=(const XdmfHDF5Writer &); // Not implemented.
+
+ virtual void controllerSplitting(XdmfArray & array,
+ int & controllerIndexOffset,
+ shared_ptr<XdmfHeavyDataController> heavyDataController,
+ const std::string & checkFileName,
+ const std::string & checkFileExt,
+ const std::string & dataSetPath,
+ int dataSetId,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ std::list<std::string> & filesWritten,
+ std::list<std::string> & datasetsWritten,
+ std::list<int> & datasetIdsWritten,
+ std::list<void *> & arraysWritten,
+ std::list<std::vector<unsigned int> > & startsWritten,
+ std::list<std::vector<unsigned int> > & stridesWritten,
+ std::list<std::vector<unsigned int> > & dimensionsWritten,
+ std::list<std::vector<unsigned int> > & dataSizesWritten,
+ std::list<unsigned int> & arrayOffsetsWritten);
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFHDF5WRITER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFHDF5WRITER XDMFHDF5WRITER;
+
+XDMFCORE_EXPORT XDMFHDF5WRITER * XdmfHDF5WriterNew(char * fileName, int clobberFile);
+
+XDMFCORE_EXPORT void XdmfHDF5WriterCloseFile(XDMFHDF5WRITER * writer, int * status);
+
+XDMFCORE_EXPORT unsigned int XdmfHDF5WriterGetChunkSize(XDMFHDF5WRITER * writer, int * status);
+
+XDMFCORE_EXPORT void XdmfHDF5WriterOpenFile(XDMFHDF5WRITER * writer, int * status);
+
+XDMFCORE_EXPORT void XdmfHDF5WriterSetChunkSize(XDMFHDF5WRITER * writer, unsigned int chunkSize, int * status);
+
+#define XDMF_HDF5WRITER_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT void ClassName##CloseFile( CClassName * writer, int * status); \
+Level##_EXPORT unsigned int ClassName##GetChunkSize( CClassName * writer, int * status); \
+Level##_EXPORT void ClassName##OpenFile( CClassName * writer, int * status); \
+Level##_EXPORT void ClassName##SetChunkSize( CClassName * writer, unsigned int chunkSize, int * status);
+
+#define XDMF_HDF5WRITER_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+void ClassName##CloseFile( CClassName * writer, int * status) \
+{ \
+ XdmfHDF5WriterCloseFile((XDMFHDF5WRITER *)((void *)writer), status); \
+} \
+ \
+unsigned int ClassName##GetChunkSize( CClassName * writer, int * status) \
+{ \
+ return XdmfHDF5WriterGetChunkSize((XDMFHDF5WRITER *)((void *)writer), status); \
+} \
+ \
+void ClassName##OpenFile( CClassName * writer, int * status) \
+{ \
+ XdmfHDF5WriterOpenFile((XDMFHDF5WRITER *)((void *)writer), status); \
+} \
+ \
+void ClassName##SetChunkSize( CClassName * writer, unsigned int chunkSize, int * status) \
+{ \
+ XdmfHDF5WriterSetChunkSize((XDMFHDF5WRITER *)((void *)writer), chunkSize, status); \
+}
+
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_HEAVYWRITER_C_CHILD_DECLARE(XdmfHDF5Writer, XDMFHDF5WRITER, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFHDF5WRITER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHeavyDataController.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <functional>
+#include <numeric>
+#include "string.h"
+#include "XdmfArrayType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfSystemUtils.hpp"
+
+XdmfHeavyDataController::XdmfHeavyDataController(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces) :
+ mStart(starts),
+ mStride(strides),
+ mDimensions(dimensions),
+ mDataspaceDimensions(dataspaces),
+ mFilePath(filePath),
+ mArrayStartOffset(0),
+ mType(type)
+{
+}
+
+XdmfHeavyDataController::XdmfHeavyDataController(const XdmfHeavyDataController& refController):
+ mStart(refController.getStart()),
+ mStride(refController.getStride()),
+ mDimensions(refController.getDimensions()),
+ mDataspaceDimensions(refController.getDataspaceDimensions()),
+ mFilePath(refController.getFilePath()),
+ mArrayStartOffset(refController.getArrayOffset()),
+ mType(refController.getType())
+{
+}
+
+XdmfHeavyDataController::~XdmfHeavyDataController()
+{
+}
+
+unsigned int
+XdmfHeavyDataController::getArrayOffset() const
+{
+ return mArrayStartOffset;
+}
+
+std::string
+XdmfHeavyDataController::getDataspaceDescription() const
+{
+ std::stringstream dimensionStream;
+
+ for (unsigned int j = 0; j < this->getStart().size(); ++j) {
+ dimensionStream << this->getStart()[j];
+ if (j < this->getStart().size() - 1) {
+ dimensionStream << " ";
+ }
+ }
+ dimensionStream << ":";
+ for (unsigned int j = 0; j < this->getStride().size(); ++j) {
+ dimensionStream << this->getStride()[j];
+ if (j < this->getStride().size() - 1) {
+ dimensionStream << " ";
+ }
+ }
+ dimensionStream << ":";
+ for (unsigned int j = 0; j < this->getDimensions().size(); ++j) {
+ dimensionStream << this->getDimensions()[j];
+ if (j < this->getDimensions().size() - 1) {
+ dimensionStream << " ";
+ }
+ }
+ dimensionStream << ":";
+ for (unsigned int j = 0; j < this->getDataspaceDimensions().size(); ++j) {
+ dimensionStream << this->getDataspaceDimensions()[j];
+ if (j < this->getDataspaceDimensions().size() - 1) {
+ dimensionStream << " ";
+ }
+ }
+ return dimensionStream.str();
+}
+
+std::vector<unsigned int>
+XdmfHeavyDataController::getDataspaceDimensions() const
+{
+ return mDataspaceDimensions;
+}
+
+unsigned int
+XdmfHeavyDataController::getDataspaceSize() const
+{
+ return std::accumulate(mDataspaceDimensions.begin(),
+ mDataspaceDimensions.end(),
+ 1,
+ std::multiplies<unsigned int>());
+}
+
+std::string
+XdmfHeavyDataController::getDescriptor() const
+{
+ return "";
+}
+
+std::vector<unsigned int>
+XdmfHeavyDataController::getDimensions() const
+{
+ return mDimensions;
+}
+
+std::string
+XdmfHeavyDataController::getFilePath() const
+{
+ return mFilePath;
+}
+
+std::vector<unsigned int>
+XdmfHeavyDataController::getStart() const
+{
+ return mStart;
+}
+
+std::vector<unsigned int>
+XdmfHeavyDataController::getStride() const
+{
+ return mStride;
+}
+
+unsigned int
+XdmfHeavyDataController::getSize() const
+{
+ return std::accumulate(mDimensions.begin(),
+ mDimensions.end(),
+ 1,
+ std::multiplies<unsigned int>());
+}
+
+shared_ptr<const XdmfArrayType>
+XdmfHeavyDataController::getType() const
+{
+ return mType;
+}
+
+void
+XdmfHeavyDataController::setArrayOffset(unsigned int newOffset)
+{
+ mArrayStartOffset = newOffset;
+}
+
+// C Wrappers
+
+void XdmfHeavyDataControllerFree(XDMFHEAVYDATACONTROLLER * item)
+{
+ if (item != NULL) {
+ delete ((XdmfHeavyDataController *)item);
+ item = NULL;
+ }
+}
+
+unsigned int * XdmfHeavyDataControllerGetDataspaceDimensions(XDMFHEAVYDATACONTROLLER * controller)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getDataspaceDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getDataspaceDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+unsigned int * XdmfHeavyDataControllerGetDimensions(XDMFHEAVYDATACONTROLLER * controller)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+char * XdmfHeavyDataControllerGetFilePath(XDMFHEAVYDATACONTROLLER * controller)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfHeavyDataController *)(controller))->getFilePath().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfHeavyDataController *)(controller))->getFilePath().c_str());
+ return returnPointer;
+ }
+}
+
+char * XdmfHeavyDataControllerGetName(XDMFHEAVYDATACONTROLLER * controller)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfHeavyDataController *)(controller))->getName().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfHeavyDataController *)(controller))->getName().c_str());
+ return returnPointer;
+ }
+}
+
+unsigned int XdmfHeavyDataControllerGetNumberDimensions(XDMFHEAVYDATACONTROLLER * controller)
+{
+ return ((XdmfHeavyDataController *)(controller))->getDimensions().size();
+}
+
+unsigned int XdmfHeavyDataControllerGetSize(XDMFHEAVYDATACONTROLLER * controller)
+{
+ return ((XdmfHeavyDataController *)(controller))->getSize();
+}
+
+unsigned int * XdmfHeavyDataControllerGetStart(XDMFHEAVYDATACONTROLLER * controller)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getStart();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getStart();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+unsigned int * XdmfHeavyDataControllerGetStride(XDMFHEAVYDATACONTROLLER * controller)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getStride();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfHeavyDataController *)(controller))->getStride();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+void XdmfHeavyDataControllerSetArrayOffset(XDMFHEAVYDATACONTROLLER * controller, unsigned int newOffset)
+{
+ ((XdmfHeavyDataController *)(controller))->setArrayOffset(newOffset);
+}
+
+unsigned int XdmfHeavyDataControllerGetArrayOffset(XDMFHEAVYDATACONTROLLER * controller)
+{
+ return ((XdmfHeavyDataController *)(controller))->getArrayOffset();
+}
+
+int XdmfHeavyDataControllerGetType(XDMFHEAVYDATACONTROLLER * controller, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<const XdmfArrayType> compareType = ((XdmfHeavyDataController *)(controller))->getType();
+ std::string typeName = compareType->getName();
+ unsigned int typePrecision = compareType->getElementSize();
+ if (typeName == XdmfArrayType::UInt8()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT8;
+ }
+ else if (typeName == XdmfArrayType::UInt16()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT16;
+ }
+ else if (typeName == XdmfArrayType::UInt32()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT32;
+ }
+ else if (typeName == XdmfArrayType::UInt64()->getName())
+ {
+ return XDMF_ARRAY_TYPE_UINT64;
+ }
+ else if (typeName == XdmfArrayType::Int8()->getName())
+ {
+ return XDMF_ARRAY_TYPE_INT8;
+ }
+ else if (typeName == XdmfArrayType::Int16()->getName())
+ {
+ return XDMF_ARRAY_TYPE_INT16;
+ }
+ else if (typeName == XdmfArrayType::Int32()->getName() || typeName == XdmfArrayType::Int64()->getName())
+ {
+ if (typePrecision == 4)
+ {
+ return XDMF_ARRAY_TYPE_INT32;
+ }
+ else if (typePrecision == 8)
+ {
+ return XDMF_ARRAY_TYPE_INT64;
+ }
+ else
+ {
+ }
+ }
+ else if (typeName == XdmfArrayType::Float32()->getName() || typeName == XdmfArrayType::Float64()->getName())
+ {
+ if (typePrecision == 4)
+ {
+ return XDMF_ARRAY_TYPE_FLOAT32;
+ }
+ else if (typePrecision == 8)
+ {
+ return XDMF_ARRAY_TYPE_FLOAT64;
+ }
+ else
+ {
+ }
+ }
+ else if (typeName == XdmfArrayType::String()->getName())
+ {
+ //This shouldn't be used from C bindings
+ XdmfError::message(XdmfError::FATAL,
+ "Error: String type not usable from C.");
+ }
+ else
+ {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+void XdmfHeavyDataControllerRead(XDMFHEAVYDATACONTROLLER * controller, void * array, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfHeavyDataController *)(controller))->read((XdmfArray *)array);
+ XDMF_ERROR_WRAP_END(status)
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHeavyDataController.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFHEAVYDATACONTROLLER_HPP_
+#define XDMFHEAVYDATACONTROLLER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfArrayType.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+// Includes
+#include <string>
+#include <vector>
+#include <map>
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief Couples an XdmfArray with heavy data stored on disk.
+ *
+ * This is an abstract base class to support the reading of different
+ * heavy data formats.
+ *
+ * Serves as an interface between data stored in XdmfArrays and data
+ * stored on disk. When an Xdmf file is read from or written to disk
+ * an XdmfHeavyController is attached to XdmfArrays. This allows data
+ * to be released from memory but still be accessible or have its
+ * location written to light data.
+ */
+class XDMFCORE_EXPORT XdmfHeavyDataController {
+
+public:
+
+ virtual ~XdmfHeavyDataController() = 0;
+
+ /**
+ * Gets a string containing data on the starts,
+ * strides, dimensions, and dataspaces for this controller.
+ *
+ * @return The string description
+ */
+ std::string getDataspaceDescription() const;
+
+ /**
+ * Get the dimensions of the dataspace owned by this
+ * controller. This is the dimension of the entire heavy dataset,
+ * which may be larger than the dimensions of the array (if reading
+ * a piece of a larger dataset).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDataspaceDimensions
+ * @until //#getDataspaceDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDataspaceDimensions
+ * @until #//getDataspaceDimensions
+ *
+ * @return A vector containing the size in each dimension of the dataspace
+ * owned by this controller.
+ */
+ std::vector<unsigned int> getDataspaceDimensions() const;
+
+ /**
+ * Get the size of dataspace of the heavy data set owned by this controller.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDataspaceSize
+ * @until //#getDataspaceSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDataspaceSize
+ * @until #//getDataspaceSize
+ *
+ * @return An int containing the size of the heavy data set.
+ */
+ unsigned int getDataspaceSize() const;
+
+ /**
+ * Gets the controller in string form. For writing to file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDescriptor
+ * @until //#getDescriptor
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDescriptor
+ * @until #//getDescriptor
+ *
+ * @return A string that contains relevant information for the controller
+ */
+ virtual std::string getDescriptor() const;
+
+ /**
+ * Get the dimensions of the heavy data set owned by this controller.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return A vector containing the size in each dimension of the heavy data
+ * set owned by this controller.
+ */
+ std::vector<unsigned int> getDimensions() const;
+
+ /**
+ * Get the absolute path to the heavy data file on disk where the
+ * data set owned by this controller resides.
+ * For "/home/output.h5:/foo/data" this is "/home/output.h5"
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getFilePath
+ * @until //#getFilePath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getFilePath
+ * @until #//getFilePath
+ *
+ * @return A std::string containing the path to the heavy data file.
+ */
+ std::string getFilePath() const;
+
+ /**
+ * Get the name of this heavy data format. E.g. "HDF" for hdf5
+ * format.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return std::string containing the name of this heavy data format
+ */
+ virtual std::string getName() const = 0;
+
+ /**
+ * Get the size of the heavy data set owned by this controller.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getSize
+ * @until //#getSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getSize
+ * @until #//getSize
+ *
+ * @return An int containing the size of the heavy data set.
+ */
+ unsigned int getSize() const;
+
+ /**
+ * Get the start index of the heavy data set owned by this controller.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getStart
+ * @until //#getStart
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getStart
+ * @until #//getStart
+ *
+ * @return A vector containing the start index in each dimension of
+ * the heavy data set owned by this controller.
+ */
+ std::vector<unsigned int> getStart() const;
+
+ /**
+ * Get the stride of the heavy data set owned by this controller.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHDF5Controller.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getStride
+ * @until //#getStride
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHDF5Controller.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getStride
+ * @until #//getStride
+ *
+ * @return A vector containing the stride in each dimension of the
+ * heavy data set owned by this controller.
+ */
+ std::vector<unsigned int> getStride() const;
+
+ /**
+ * For use in conjunction with heavy data controllers set to arrays
+ * the offset within the array from which the controller will be inserted
+ * Is also set when created by a writer.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setArrayOffset
+ * @until //#setArrayOffset
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setArrayOffset
+ * @until #//setArrayOffset
+ *
+ * @param newOffset The new index at which the controller will be written
+ */
+ void setArrayOffset(unsigned int newOffset);
+
+ /**
+ * Gets the index at which the controller will offset when
+ * an array reads it from its associated controllers.
+ * Set when created by a Writer or set manually.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setArrayOffset
+ * @until //#setArrayOffset
+ * @skipline //#getArrayOffset
+ * @until //#getArrayOffset
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setArrayOffset
+ * @until #//setArrayOffset
+ * @skipline #//getArrayOffset
+ * @until #//getArrayOffset
+ *
+ * @return The offset that the array will read from
+ */
+ unsigned int getArrayOffset() const;
+
+ virtual void getProperties(std::map<std::string, std::string> & collectedProperties) const = 0;
+
+ /**
+ * Get the array type of the heavy data set owned by this
+ * controller.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getType
+ * @until //#getType
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getType
+ * @until #//getType
+ *
+ * @return An XdmfArrayType containing the array type of the heavy data set.
+ */
+ shared_ptr<const XdmfArrayType> getType() const;
+
+ /**
+ * Read data owned by this controller on disk into the passed
+ * XdmfArray.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//read
+ * @until #//read
+ *
+ * @param array An XdmfArray to read data into.
+ */
+ virtual void read(XdmfArray * const array) = 0;
+
+ XdmfHeavyDataController(const XdmfHeavyDataController&);
+
+protected:
+
+ XdmfHeavyDataController(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces);
+
+ const std::vector<unsigned int> mStart;
+ const std::vector<unsigned int> mStride;
+ const std::vector<unsigned int> mDimensions;
+ const std::vector<unsigned int> mDataspaceDimensions;
+ const std::string mFilePath;
+ unsigned int mArrayStartOffset;
+ const shared_ptr<const XdmfArrayType> mType;
+
+private:
+
+ void operator=(const XdmfHeavyDataController &); // Not implemented.
+
+};
+
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFHEAVYDATACONTROLLER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFHEAVYDATACONTROLLER XDMFHEAVYDATACONTROLLER;
+
+XDMFCORE_EXPORT void XdmfHeavyDataControllerFree(XDMFHEAVYDATACONTROLLER * item);
+
+XDMFCORE_EXPORT unsigned int * XdmfHeavyDataControllerGetDataspaceDimensions(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT unsigned int * XdmfHeavyDataControllerGetDimensions(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT char * XdmfHeavyDataControllerGetFilePath(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT char * XdmfHeavyDataControllerGetName(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT unsigned int XdmfHeavyDataControllerGetNumberDimensions(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT unsigned int XdmfHeavyDataControllerGetSize(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT unsigned int * XdmfHeavyDataControllerGetStart(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT unsigned int * XdmfHeavyDataControllerGetStride(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT void XdmfHeavyDataControllerSetArrayOffset(XDMFHEAVYDATACONTROLLER * controller, unsigned int newOffset);
+
+XDMFCORE_EXPORT unsigned int XdmfHeavyDataControllerGetArrayOffset(XDMFHEAVYDATACONTROLLER * controller);
+
+XDMFCORE_EXPORT int XdmfHeavyDataControllerGetType(XDMFHEAVYDATACONTROLLER * controller, int * status);
+
+XDMFCORE_EXPORT void XdmfHeavyDataControllerRead(XDMFHEAVYDATACONTROLLER * controller, void * array, int * status);
+
+#define XDMF_HEAVYCONTROLLER_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT void ClassName##Free( CClassName * item); \
+Level##_EXPORT unsigned int * ClassName##GetDataspaceDimensions( CClassName * controller); \
+Level##_EXPORT unsigned int * ClassName##GetDimensions( CClassName * controller); \
+Level##_EXPORT char * ClassName##GetFilePath( CClassName * controller); \
+Level##_EXPORT char * ClassName##GetName( CClassName * controller); \
+Level##_EXPORT unsigned int ClassName##GetNumberDimensions( CClassName * controller); \
+Level##_EXPORT unsigned int ClassName##GetSize( CClassName * controller); \
+Level##_EXPORT unsigned int * ClassName##GetStart( CClassName * controller); \
+Level##_EXPORT unsigned int * ClassName##GetStride( CClassName * controller); \
+Level##_EXPORT void ClassName##SetArrayOffset( CClassName * controller, unsigned int newOffset); \
+Level##_EXPORT unsigned int ClassName##GetArrayOffset( CClassName * controller); \
+Level##_EXPORT int ClassName##GetType( CClassName * controller, int * status); \
+Level##_EXPORT void ClassName##Read( CClassName * controller, void * array, int * status);
+
+
+
+#define XDMF_HEAVYCONTROLLER_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+void ClassName##Free( CClassName * item) \
+{ \
+ XdmfHeavyDataControllerFree((XDMFHEAVYDATACONTROLLER *)((void *)item)); \
+} \
+ \
+unsigned int * ClassName##GetDataspaceDimensions( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetDataspaceDimensions((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+unsigned int * ClassName##GetDimensions( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetDimensions((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+char * ClassName##GetFilePath( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetFilePath((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+char * ClassName##GetName( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetName((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+unsigned int ClassName##GetNumberDimensions( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetNumberDimensions((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+unsigned int ClassName##GetSize( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetSize((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+unsigned int * ClassName##GetStart( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetStart((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+unsigned int * ClassName##GetStride( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetStride((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+void ClassName##SetArrayOffset( CClassName * controller, unsigned int newOffset) \
+{ \
+ XdmfHeavyDataControllerSetArrayOffset((XDMFHEAVYDATACONTROLLER *)((void *)controller), newOffset); \
+} \
+ \
+unsigned int ClassName##GetArrayOffset( CClassName * controller) \
+{ \
+ return XdmfHeavyDataControllerGetArrayOffset((XDMFHEAVYDATACONTROLLER *)((void *)controller)); \
+} \
+ \
+int ClassName##GetType( CClassName * controller, int * status) \
+{ \
+ return XdmfHeavyDataControllerGetType((XDMFHEAVYDATACONTROLLER *)((void *)controller), status); \
+} \
+ \
+void ClassName##Read( CClassName * controller, void * array, int * status) \
+{ \
+ XdmfHeavyDataControllerRead((XDMFHEAVYDATACONTROLLER *)((void *)controller), array, status); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFHEAVYDATACONTROLLER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHeavyDataDescription.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+#include <utility>
+#include "XdmfError.hpp"
+#include "XdmfHeavyDataDescription.hpp"
+#include "XdmfSharedPtr.hpp"
+#include "XdmfVisitor.hpp"
+#include "string.h"
+
+shared_ptr<XdmfHeavyDataDescription>
+XdmfHeavyDataDescription::New()
+{
+ shared_ptr<XdmfHeavyDataDescription> p(new XdmfHeavyDataDescription());
+ return p;
+}
+
+XdmfHeavyDataDescription::XdmfHeavyDataDescription()
+{
+}
+
+XdmfHeavyDataDescription::XdmfHeavyDataDescription(XdmfHeavyDataDescription & refDescription) :
+ XdmfItem(refDescription)
+{
+}
+
+XdmfHeavyDataDescription::~XdmfHeavyDataDescription()
+{
+}
+
+const std::string XdmfHeavyDataDescription::ItemTag = "HeavyData";
+
+std::map<std::string, std::string>
+XdmfHeavyDataDescription::getItemProperties() const
+{
+ std::map<std::string, std::string> descriptionProperties;
+ return descriptionProperties;
+}
+
+std::string
+XdmfHeavyDataDescription::getItemTag() const
+{
+ return ItemTag;
+}
+
+void
+XdmfHeavyDataDescription::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+}
+
+void
+XdmfHeavyDataDescription::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+
+}
+
+// C Wrappers
+
+XDMFHEAVYDATADESCRIPTION *
+XdmfHeavyDataDescriptionNew(char * key, char * value)
+{
+ std::string createKey(key);
+ std::string createValue(value);
+ shared_ptr<XdmfHeavyDataDescription> generatedDesc = XdmfHeavyDataDescription::New();
+ return (XDMFHEAVYDATADESCRIPTION *)((void *)(new XdmfHeavyDataDescription(*generatedDesc.get())));
+}
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfHeavyDataDescription, XDMFHEAVYDATADESCRIPTION)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHeavyDataDescription.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+#ifndef XDMFHEAVYDATADESCRIPTION_HPP_
+#define XDMFHEAVYDATADESCRIPTION_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfItem.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Holds information about a dsm buffer so that a process can connect.
+ *
+ * XdmfDescription stores the information required to process
+ * to a data format
+ */
+class XDMFCORE_EXPORT XdmfHeavyDataDescription : public XdmfItem {
+
+public:
+
+ /**
+ *
+ */
+ static shared_ptr<XdmfHeavyDataDescription> New();
+
+ virtual ~XdmfHeavyDataDescription();
+
+ LOKI_DEFINE_VISITABLE(XdmfHeavyDataDescription, XdmfItem)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ virtual std::string getItemTag() const;
+
+ std::string getPortDescription() const;
+
+ using XdmfItem::insert;
+
+ void setPortDescription(std::string portDesc);
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfHeavyDataDescription(XdmfHeavyDataDescription &);
+
+protected:
+
+ XdmfHeavyDataDescription();
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfHeavyDataDescription(const XdmfHeavyDataDescription &); // Not implemented.
+ void operator=(const XdmfHeavyDataDescription &); // Not implemented.
+
+ std::string mPortDescription;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFHEAVYDATADESCRIPTION; // Simply as a typedef to ensure correct typing
+typedef struct XDMFHEAVYDATADESCRIPTION XDMFHEAVYDATADESCRIPTION;
+
+XDMFCORE_EXPORT XDMFHEAVYDATADESCRIPTION * XdmfHeavyDataDescriptionNew();
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfHeavyDataDescription, XDMFHEAVYDATADESCRIPTION, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFHeavyDataDESCRIPTION_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHeavyDataWriter.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfHeavyDataWriter.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfSystemUtils.hpp"
+#include <cstdio>
+#include <list>
+#include <vector>
+#include "string.h"
+
+XdmfHeavyDataWriter::XdmfHeavyDataWriter(const double compression,
+ const unsigned int overhead) :
+ mAllowSplitDataSets(false),
+ mDataSetId(0),
+ mFileIndex(0),
+ mFilePath(""),
+ mFileSizeLimit(0),
+ mMode(Default),
+ mCompressionRatio(compression),
+ mFileOverhead(overhead)
+{
+}
+
+XdmfHeavyDataWriter::XdmfHeavyDataWriter(const std::string & filePath,
+ const double compression,
+ const unsigned int overhead) :
+ mAllowSplitDataSets(false),
+ mDataSetId(0),
+ mFileIndex(0),
+ mFilePath(XdmfSystemUtils::getRealPath(filePath)),
+ mFileSizeLimit(0),
+ mMode(Default),
+ mReleaseData(false),
+ mCompressionRatio(compression),
+ mFileOverhead(overhead)
+{
+}
+
+XdmfHeavyDataWriter::~XdmfHeavyDataWriter()
+{
+}
+
+int
+XdmfHeavyDataWriter::getAllowSetSplitting()
+{
+ return mAllowSplitDataSets;
+}
+
+int
+XdmfHeavyDataWriter::getFileIndex()
+{
+ return mFileIndex;
+}
+
+unsigned int
+XdmfHeavyDataWriter::getFileOverhead()
+{
+ return mFileOverhead;
+}
+
+std::string
+XdmfHeavyDataWriter::getFilePath() const
+{
+ if (mFilePath.c_str() == NULL) {
+ return "";
+ }
+ else {
+ return mFilePath;
+ }
+}
+
+int
+XdmfHeavyDataWriter::getFileSizeLimit()
+{
+ return mFileSizeLimit;
+}
+
+XdmfHeavyDataWriter::Mode
+XdmfHeavyDataWriter::getMode() const
+{
+ return mMode;
+}
+
+bool
+XdmfHeavyDataWriter::getReleaseData() const
+{
+ return mReleaseData;
+}
+
+void
+XdmfHeavyDataWriter::setAllowSetSplitting(bool newAllow)
+{
+ mAllowSplitDataSets = newAllow;
+}
+
+void
+XdmfHeavyDataWriter::setFileIndex(int newSize)
+{
+ mFileIndex = newSize;
+}
+
+void
+XdmfHeavyDataWriter::setFileSizeLimit(int newSize)
+{
+ mFileSizeLimit = newSize;
+}
+
+void
+XdmfHeavyDataWriter::setMode(const Mode mode)
+{
+ mMode = mode;
+}
+
+void
+XdmfHeavyDataWriter::setReleaseData(const bool releaseData)
+{
+ mReleaseData = releaseData;
+}
+
+// C Wrappers
+
+void XdmfHeavyDataWriterFree(XDMFHEAVYDATAWRITER * item)
+{
+ if (item != NULL) {
+ delete ((XdmfHeavyDataWriter *)item);
+ item = NULL;
+ }
+}
+
+int XdmfHeavyDataWriterGetAllowSetSplitting(XDMFHEAVYDATAWRITER * writer)
+{
+ return ((XdmfHeavyDataWriter *)writer)->getAllowSetSplitting();
+}
+
+int XdmfHeavyDataWriterGetFileIndex(XDMFHEAVYDATAWRITER * writer)
+{
+ return ((XdmfHeavyDataWriter *)writer)->getFileIndex();
+}
+
+unsigned int XdmfHeavyDataWriterGetFileOverhead(XDMFHEAVYDATAWRITER * writer)
+{
+ return ((XdmfHeavyDataWriter *)writer)->getFileOverhead();
+}
+
+char * XdmfHeavyDataWriterGetFilePath(XDMFHEAVYDATAWRITER * writer)
+{
+ try
+ {
+ char * returnPointer = strdup(((XdmfHeavyDataWriter *)writer)->getFilePath().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfHeavyDataWriter *)writer)->getFilePath().c_str());
+ return returnPointer;
+ }
+}
+
+int XdmfHeavyDataWriterGetFileSizeLimit(XDMFHEAVYDATAWRITER * writer)
+{
+ return ((XdmfHeavyDataWriter *)writer)->getFileSizeLimit();
+}
+
+int XdmfHeavyDataWriterGetMode(XDMFHEAVYDATAWRITER * writer)
+{
+ XdmfHeavyDataWriter::Mode checkMode = ((XdmfHeavyDataWriter *)writer)->getMode();
+ if (checkMode == XdmfHeavyDataWriter::Default) {
+ return XDMF_HEAVY_WRITER_MODE_DEFAULT;
+ }
+ else if (checkMode == XdmfHeavyDataWriter::Overwrite) {
+ return XDMF_HEAVY_WRITER_MODE_OVERWRITE;
+ }
+ else if (checkMode == XdmfHeavyDataWriter::Append) {
+ return XDMF_HEAVY_WRITER_MODE_APPEND;
+ }
+ else if (checkMode == XdmfHeavyDataWriter::Hyperslab) {
+ return XDMF_HEAVY_WRITER_MODE_HYPERSLAB;
+ }
+ return -1;
+}
+
+int XdmfHeavyDataWriterGetReleaseData(XDMFHEAVYDATAWRITER * writer)
+{
+ return ((XdmfHeavyDataWriter *)writer)->getReleaseData();
+}
+
+void XdmfHeavyDataWriterSetAllowSetSplitting(XDMFHEAVYDATAWRITER * writer, int newAllow)
+{
+ ((XdmfHeavyDataWriter *)writer)->setAllowSetSplitting(newAllow);
+}
+
+void XdmfHeavyDataWriterSetFileIndex(XDMFHEAVYDATAWRITER * writer, int newIndex)
+{
+ ((XdmfHeavyDataWriter *)writer)->setFileIndex(newIndex);
+}
+
+void XdmfHeavyDataWriterSetFileSizeLimit(XDMFHEAVYDATAWRITER * writer, int newSize)
+{
+ ((XdmfHeavyDataWriter *)writer)->setFileSizeLimit(newSize);
+}
+
+void XdmfHeavyDataWriterSetMode(XDMFHEAVYDATAWRITER * writer, int mode, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfHeavyDataWriter::Mode newMode;
+ switch (mode) {
+ case XDMF_HEAVY_WRITER_MODE_DEFAULT:
+ newMode = XdmfHeavyDataWriter::Default;
+ break;
+ case XDMF_HEAVY_WRITER_MODE_OVERWRITE:
+ newMode = XdmfHeavyDataWriter::Overwrite;
+ break;
+ case XDMF_HEAVY_WRITER_MODE_APPEND:
+ newMode = XdmfHeavyDataWriter::Append;
+ break;
+ case XDMF_HEAVY_WRITER_MODE_HYPERSLAB:
+ newMode = XdmfHeavyDataWriter::Hyperslab;
+ break;
+ default:
+ newMode = XdmfHeavyDataWriter::Default;
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid heavy writer mode.");
+ }
+ ((XdmfHeavyDataWriter *)writer)->setMode(newMode);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfHeavyDataWriterSetReleaseData(XDMFHEAVYDATAWRITER * writer, int releaseData)
+{
+ ((XdmfHeavyDataWriter *)writer)->setReleaseData(releaseData);
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfHeavyDataWriter.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFHEAVYDATAWRITER_HPP_
+#define XDMFHEAVYDATAWRITER_HPP_
+
+#include "XdmfCore.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfHeavyDataController.hpp"
+#include "XdmfVisitor.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+// Includes
+#include <string>
+#include <list>
+
+/**
+ * @brief Traverses the Xdmf graph and writes heavy data stored in
+ * XdmfArrays to heavy data files on disk.
+ *
+ * This is an abstract base class to support the writing of different
+ * heavy data formats.
+ *
+ * XdmfHeavyDataWriter traverses an Xdmf graph structure and writes
+ * data stored in XdmfArrays to heavy data files on disk. Writing
+ * begins by calling the accept() operation on any XdmfItem and
+ * supplying this writer as the parameter. The writer will write all
+ * XdmfArrays under the XdmfItem to a heavy data file on disk. It will
+ * also attach an XdmfHeavyDataController to all XdmfArrays that it
+ * writes to disk.
+ *
+ * There are three modes of operation for this writer:
+ * Default - All initialized XdmfArrays are written to new heavy datasets
+ * regardless of whether they are attached to another heavy
+ * dataset on disk via an XdmfHeavyDataController.
+ * Overwrite - If an initialized XdmfArray is attached to an heavy dataset
+ * via an XdmfHeavyDataController the writer will write values
+ * to that location, overwriting all previous written values.
+ * The dataset on disk will be resized appropriately.
+ * Append - If an initialized XdmfArray is attached to an heavy dataset via
+ * an XdmfHeavyDataController the writer will append the values to
+ * the end of the dataset on disk.
+ * Hyperslab - If an initialized XdmfArray is attached to a heavy dataset
+ * via an XdmfHeavyDataController the writer will write to a
+ * hyperslab in the dataset based on the start, stride, and
+ * dimensions of the XdmfHeavyDataController.
+ */
+class XDMFCORE_EXPORT XdmfHeavyDataWriter : public XdmfVisitor,
+ public Loki::Visitor<XdmfArray> {
+
+public:
+
+ enum Mode {
+ Default,
+ Overwrite,
+ Append,
+ Hyperslab
+ };
+
+ virtual ~XdmfHeavyDataWriter() = 0;
+
+ /**
+ * Close file. This is only needed when the file is opened manually
+ * through openFile().
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#closeFile
+ * @until //#closeFile
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//closeFile
+ * @until #//closeFile
+ */
+ virtual void closeFile() = 0;
+
+ /**
+ * Gets whether the HDF5 Writer is allowed to split data sets when writing to hdf5.
+ * Splitting should only occur for massive data sets.
+ * Setting to false assures compatibility with previous editions.
+ * Default setting is false.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getAllowSetSplitting
+ * @until //#getAllowSetSplitting
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getAllowSetSplitting
+ * @until #//getAllowSetSplitting
+ *
+ * @return Whether to allow data sets to be split across hdf5 files
+ */
+ int getAllowSetSplitting();
+
+ /**
+ * Gets the file index. Used when file splitting and incremented whent he current file is full.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getFileIndex
+ * @until //#getFileIndex
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getFileIndex
+ * @until #//getFileIndex
+ *
+ * @return The current file index.
+ */
+ int getFileIndex();
+
+ /**
+ * Gets the amount of bytes that the heavy data writer uses as overhead for the data type.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getFileOverhead
+ * @until //#getFileOverhead
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getFileOverhead
+ * @until #//getFileOverhead
+ *
+ * @return Amount of bytes used as overhead
+ */
+ unsigned int getFileOverhead();
+
+ /**
+ * Get the path to the heavy data file on disk this writer is writing to.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getFilePath
+ * @until //#getFilePath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getFilePath
+ * @until #//getFilePath
+ *
+ * @return A std::string containing the path to the heavy file on disk this
+ * writer is writing to.
+ */
+ std::string getFilePath() const;
+
+ /**
+ * Gets the file size limit of the HDF5 files produced by the writer in MB. Overflow is pushed to a new HDF5 file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getFileSizeLimit
+ * @until //#getFileSizeLimit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getFileSizeLimit
+ * @until #//getFileSizeLimit
+ *
+ * @return The size limit in MB
+ */
+ int getFileSizeLimit();
+
+ /**
+ * Get the Mode of operation for this writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getMode
+ * @until //#getMode
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getMode
+ * @until #//getMode
+ *
+ * @return The Mode of operation for this writer.
+ */
+ Mode getMode() const;
+
+ /**
+ * Get whether to release data from memory after writing to disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getReleaseData
+ * @until //#getReleaseData
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getReleaseData
+ * @until #//getReleaseData
+ *
+ * @return True if data is freed after writing
+ */
+ bool getReleaseData() const;
+
+ /**
+ * Open file for writing. This is an optional command that can
+ * improve performance for some writers when writing many datasets
+ * to a single file. User must call closeFile() after completing
+ * output.
+ *
+ * By default, heavy data files are open and closed before and after
+ * writing each dataset to ensure that other writers have access to
+ * the file (we never know whether we will be writing to the file
+ * again). This is expensive in some cases, but is always
+ * safe. Opening the file once and writing many datasets may result
+ * in improved performance, but the user must tell the writer when
+ * to open and close the file.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#openFile
+ * @until //#openFile
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//openFile
+ * @until #//openFile
+ */
+ virtual void openFile() = 0;
+
+ /**
+ * Sets whether to allow the HDF5 writer to split data sets when writing to hdf5.
+ * Splitting should only occur for massive data sets.
+ * Setting to false assures compatibility with previous editions.
+ * Default setting is false
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setAllowSetSplitting
+ * @until //#setAllowSetSplitting
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setAllowSetSplitting
+ * @until #//setAllowSetSplitting
+ *
+ * @param newAllow Whether to allow data sets to be split across hdf5 files
+ */
+ void setAllowSetSplitting(bool newAllow);
+
+ /**
+ * Sets the file index. Used when file splitting and incremented when the current file is full. Set to 0 before using hyperslab or overwrite.
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getFileIndex
+ * @until //#getFileIndex
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getFileIndex
+ * @until #//getFileIndex
+ *
+ * @param newIndex The index that the writer will append to the file name when incorperating file splitting
+ */
+ void setFileIndex(int newIndex);
+
+ /**
+ * Sets the file size limit of the HDF5 files produced by the writer in MB. Overflow is pushed to a new HDF5 file.
+ * Using with arrays of string type may reduce performance.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setFileSizeLimit
+ * @until //#setFileSizeLimit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setFileSizeLimit
+ * @until #//setFileSizeLimit
+ *
+ * @param newSize The size limit in MB
+ */
+ void setFileSizeLimit(int newSize);
+
+ /**
+ * Set the mode of operation for this writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setMode
+ * @until //#setMode
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setMode
+ * @until #//setMode
+ *
+ * @param mode The Mode of operation for this writer.
+ */
+ void setMode(const Mode mode);
+
+ /**
+ * Set whether to release data from memory after writing to disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setReleaseData
+ * @until //#setReleaseData
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setReleaseData
+ * @until #//setReleaseData
+ *
+ * @param releaseData True if data should be freed after writing
+ */
+ void setReleaseData(const bool releaseData = true);
+
+ /**
+ * Write an XdmfArray to heavy data file on disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfHeavyDataWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#visit
+ * @until //#visit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleHeavyDataWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//visit
+ * @until #//visit
+ *
+ * @param array An XdmfArray to write to heavy data.
+ * @param visitor A smart pointer to this visitor --- aids in grid traversal.
+ */
+ using XdmfVisitor::visit;
+ virtual void visit(XdmfArray & array,
+ const shared_ptr<XdmfBaseVisitor> visitor) = 0;
+
+protected:
+
+ XdmfHeavyDataWriter(const double compression = 1, const unsigned int overhead = 0);
+ XdmfHeavyDataWriter(const std::string & filePath, const double compression = 1, const unsigned int overhead = 0);
+
+ virtual shared_ptr<XdmfHeavyDataController>
+ createController(const std::string & filePath,
+ const std::string & descriptor,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions) = 0;
+
+ virtual int getDataSetSize(shared_ptr<XdmfHeavyDataController> descriptionController) = 0;
+
+ bool mAllowSplitDataSets;
+ int mDataSetId;
+ int mFileIndex;
+ std::string mFilePath;
+ unsigned int mFileSizeLimit;
+ Mode mMode;
+ bool mReleaseData;
+ double mCompressionRatio;
+ unsigned int mFileOverhead;
+
+private:
+
+ XdmfHeavyDataWriter(const XdmfHeavyDataWriter &); // Not implemented.
+ void operator=(const XdmfHeavyDataWriter &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct XDMFHEAVYDATAWRITER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFHEAVYDATAWRITER XDMFHEAVYDATAWRITER;
+
+#define XDMF_HEAVY_WRITER_MODE_DEFAULT 20
+#define XDMF_HEAVY_WRITER_MODE_OVERWRITE 21
+#define XDMF_HEAVY_WRITER_MODE_APPEND 22
+#define XDMF_HEAVY_WRITER_MODE_HYPERSLAB 23
+
+// C wrappers go here
+
+XDMFCORE_EXPORT void XdmfHeavyDataWriterFree(XDMFHEAVYDATAWRITER * item);
+
+XDMFCORE_EXPORT int XdmfHeavyDataWriterGetAllowSetSplitting(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT int XdmfHeavyDataWriterGetFileIndex(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT unsigned int XdmfHeavyDataWriterGetFileOverhead(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT char * XdmfHeavyDataWriterGetFilePath(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT int XdmfHeavyDataWriterGetFileSizeLimit(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT int XdmfHeavyDataWriterGetMode(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT int XdmfHeavyDataWriterGetReleaseData(XDMFHEAVYDATAWRITER * writer);
+
+XDMFCORE_EXPORT void XdmfHeavyDataWriterSetAllowSetSplitting(XDMFHEAVYDATAWRITER * writer, int newAllow);
+
+XDMFCORE_EXPORT void XdmfHeavyDataWriterSetFileIndex(XDMFHEAVYDATAWRITER * writer, int newIndex);
+
+XDMFCORE_EXPORT void XdmfHeavyDataWriterSetFileSizeLimit(XDMFHEAVYDATAWRITER * writer, int newSize);
+
+XDMFCORE_EXPORT void XdmfHeavyDataWriterSetMode(XDMFHEAVYDATAWRITER * writer, int mode, int * status);
+
+XDMFCORE_EXPORT void XdmfHeavyDataWriterSetReleaseData(XDMFHEAVYDATAWRITER * writer, int releaseData);
+
+#define XDMF_HEAVYWRITER_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT void ClassName##Free( CClassName * item); \
+Level##_EXPORT int ClassName##GetAllowSetSplitting( CClassName * writer); \
+Level##_EXPORT int ClassName##GetFileIndex( CClassName * writer); \
+Level##_EXPORT unsigned int ClassName##GetFileOverhead( CClassName * writer); \
+Level##_EXPORT char * ClassName##GetFilePath( CClassName * writer); \
+Level##_EXPORT int ClassName##GetFileSizeLimit( CClassName * writer); \
+Level##_EXPORT int ClassName##GetMode( CClassName * writer); \
+Level##_EXPORT int ClassName##GetReleaseData( CClassName * writer); \
+Level##_EXPORT void ClassName##SetAllowSetSplitting( CClassName * writer, int newAllow); \
+Level##_EXPORT void ClassName##SetFileIndex( CClassName * writer, int newIndex); \
+Level##_EXPORT void ClassName##SetFileSizeLimit( CClassName * writer, int newSize); \
+Level##_EXPORT void ClassName##SetMode( CClassName * writer, int mode, int * status); \
+Level##_EXPORT void ClassName##SetReleaseData( CClassName * writer, int releaseData);
+
+
+
+#define XDMF_HEAVYWRITER_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+void ClassName##Free( CClassName * item) \
+{ \
+ XdmfHeavyDataWriterFree((XDMFHEAVYDATAWRITER *)((void *)item)); \
+} \
+ \
+int ClassName##GetAllowSetSplitting( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetAllowSetSplitting((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+int ClassName##GetFileIndex( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetFileIndex((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+unsigned int ClassName##GetFileOverhead( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetFileOverhead((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+char * ClassName##GetFilePath( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetFilePath((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+int ClassName##GetFileSizeLimit( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetFileSizeLimit((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+int ClassName##GetMode( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetMode((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+int ClassName##GetReleaseData( CClassName * writer) \
+{ \
+ return XdmfHeavyDataWriterGetReleaseData((XDMFHEAVYDATAWRITER *)((void *)writer)); \
+} \
+ \
+void ClassName##SetAllowSetSplitting( CClassName * writer, int newAllow) \
+{ \
+ XdmfHeavyDataWriterSetAllowSetSplitting((XDMFHEAVYDATAWRITER *)((void *)writer), newAllow); \
+} \
+ \
+void ClassName##SetFileIndex( CClassName * writer, int newIndex) \
+{ \
+ XdmfHeavyDataWriterSetFileIndex((XDMFHEAVYDATAWRITER *)((void *)writer), newIndex); \
+} \
+ \
+void ClassName##SetFileSizeLimit( CClassName * writer, int newSize) \
+{ \
+ XdmfHeavyDataWriterSetFileSizeLimit((XDMFHEAVYDATAWRITER *)((void *)writer), newSize); \
+} \
+ \
+void ClassName##SetMode( CClassName * writer, int mode, int * status) \
+{ \
+ XdmfHeavyDataWriterSetMode((XDMFHEAVYDATAWRITER *)((void *)writer), mode, status); \
+} \
+ \
+void ClassName##SetReleaseData( CClassName * writer, int releaseData) \
+{ \
+ XdmfHeavyDataWriterSetReleaseData((XDMFHEAVYDATAWRITER *)((void *)writer), releaseData); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFHEAVYDATAWRITER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfInformation.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <utility>
+#include "string.h"
+#include "XdmfArray.hpp"
+#include "XdmfError.hpp"
+#include "XdmfInformation.hpp"
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfInformation, XdmfArray, Array, Name)
+
+shared_ptr<XdmfInformation>
+XdmfInformation::New()
+{
+ shared_ptr<XdmfInformation> p(new XdmfInformation());
+ return p;
+}
+
+shared_ptr<XdmfInformation>
+XdmfInformation::New(const std::string & key,
+ const std::string & value)
+{
+ shared_ptr<XdmfInformation> p(new XdmfInformation(key, value));
+ return p;
+}
+
+XdmfInformation::XdmfInformation(const std::string & key,
+ const std::string & value) :
+ mKey(key),
+ mValue(value)
+{
+}
+
+XdmfInformation::XdmfInformation(XdmfInformation & refInfo) :
+ XdmfItem(refInfo),
+ mArrays(refInfo.mArrays)
+{
+ mKey = refInfo.getKey();
+ mValue = refInfo.getValue();
+}
+
+XdmfInformation::~XdmfInformation()
+{
+}
+
+const std::string XdmfInformation::ItemTag = "Information";
+
+std::map<std::string, std::string>
+XdmfInformation::getItemProperties() const
+{
+ std::map<std::string, std::string> informationProperties;
+ informationProperties.insert(std::make_pair("Name", mKey));
+ informationProperties.insert(std::make_pair("Value", mValue));
+ return informationProperties;
+}
+
+std::string
+XdmfInformation::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::string
+XdmfInformation::getKey() const
+{
+ return mKey;
+}
+
+std::string
+XdmfInformation::getValue() const
+{
+ return mValue;
+}
+
+void
+XdmfInformation::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+
+ std::map<std::string, std::string>::const_iterator key =
+ itemProperties.find("Name");
+ if(key != itemProperties.end()) {
+ mKey = key->second;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'Name' not found in itemProperties in "
+ "XdmfInformation::populateItem");
+ }
+
+ std::map<std::string, std::string>::const_iterator value =
+ itemProperties.find("Value");
+ if(value != itemProperties.end()) {
+ mValue = value->second;
+ }
+ else {
+ value = itemProperties.find("Content");
+ if(value != itemProperties.end()) {
+ mValue = value->second;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'Value' not found in itemProperties in "
+ "XdmfInformation::populateItem");
+ }
+ }
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ this->insert(array);
+ }
+ }
+}
+
+void
+XdmfInformation::setKey(const std::string & key)
+{
+ mKey = key;
+ this->setIsChanged(true);
+}
+
+void
+XdmfInformation::setValue(const std::string & value)
+{
+ mValue = value;
+ this->setIsChanged(true);
+}
+
+void
+XdmfInformation::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+ for (unsigned int i = 0; i < mArrays.size(); ++i)
+ {
+ mArrays[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+XDMFINFORMATION *
+XdmfInformationNew(char * key, char * value)
+{
+ try
+ {
+ std::string createKey(key);
+ std::string createValue(value);
+ shared_ptr<XdmfInformation> generatedInfo = XdmfInformation::New(createKey, createValue);
+ return (XDMFINFORMATION *)((void *)(new XdmfInformation(*generatedInfo.get())));
+ }
+ catch (...)
+ {
+ std::string createKey(key);
+ std::string createValue(value);
+ shared_ptr<XdmfInformation> generatedInfo = XdmfInformation::New(createKey, createValue);
+ return (XDMFINFORMATION *)((void *)(new XdmfInformation(*generatedInfo.get())));
+ }
+}
+
+XDMFARRAY *
+XdmfInformationGetArray(XDMFINFORMATION * information, unsigned int index)
+{
+ return (XDMFARRAY *)((void *)(((XdmfInformation *)(information))->getArray(index).get()));
+}
+
+XDMFARRAY *
+XdmfInformationGetArrayByName(XDMFINFORMATION * information, char * name)
+{
+ return (XDMFARRAY *)((void *)(((XdmfInformation *)(information))->getArray(name).get()));
+}
+
+char *
+XdmfInformationGetKey(XDMFINFORMATION * information)
+{
+ try
+ {
+ XdmfInformation referenceInfo = *(XdmfInformation *)(information);
+ char * returnPointer = strdup(referenceInfo.getKey().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ XdmfInformation referenceInfo = *(XdmfInformation *)(information);
+ char * returnPointer = strdup(referenceInfo.getKey().c_str());
+ return returnPointer;
+ }
+}
+
+unsigned int
+XdmfInformationGetNumberArrays(XDMFINFORMATION * information)
+{
+ return ((XdmfInformation *)(information))->getNumberArrays();
+}
+
+char *
+XdmfInformationGetValue(XDMFINFORMATION * information)
+{
+ try
+ {
+ XdmfInformation referenceInfo = *(XdmfInformation *)(information);
+ char * returnPointer = strdup(referenceInfo.getValue().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ XdmfInformation referenceInfo = *(XdmfInformation *)(information);
+ char * returnPointer = strdup(referenceInfo.getValue().c_str());
+ return returnPointer;
+ }
+}
+
+void
+XdmfInformationInsertArray(XDMFINFORMATION * information, XDMFARRAY * array, int transferOwnership)
+{
+ if (transferOwnership) {
+ ((XdmfInformation *)(information))->insert(shared_ptr<XdmfArray>((XdmfArray *)array));
+ }
+ else {
+ ((XdmfInformation *)(information))->insert(shared_ptr<XdmfArray>((XdmfArray *)array, XdmfNullDeleter()));
+ }
+}
+
+void
+XdmfInformationRemoveArray(XDMFINFORMATION * information, unsigned int index)
+{
+ ((XdmfInformation *)(information))->removeArray(index);
+}
+
+void
+XdmfInformationRemoveArrayByName(XDMFINFORMATION * information, char * name)
+{
+ ((XdmfInformation *)(information))->removeArray(name);
+}
+
+void
+XdmfInformationSetKey(XDMFINFORMATION * information, char * key, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfInformation *)(information))->setKey(key);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void
+XdmfInformationSetValue(XDMFINFORMATION * information, char * value, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfInformation *)(information))->setValue(value);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfInformation, XDMFINFORMATION)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfInformation.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFINFORMATION_HPP_
+#define XDMFINFORMATION_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfArray.hpp"
+
+#ifdef __cplusplus
+
+// Forward declarations
+class XdmfArray;
+
+/**
+ * @brief Holds a key/value pair that can be attached to an Xdmf
+ * structure.
+ *
+ * XdmfInformation stores two strings as a key value pair. These can
+ * be used to store input parameters to a code or for simple result
+ * data like wall time.
+ */
+class XDMFCORE_EXPORT XdmfInformation : public XdmfItem {
+
+public:
+
+ /**
+ * Create a new XdmfInformation.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfInformation.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleInformation.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @return Constructed XdmfInformation.
+ */
+ static shared_ptr<XdmfInformation> New();
+
+ /**
+ * Create a new XdmfInformation.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfInformation.cpp
+ * @skipline //#initializationfull
+ * @until //#initializationfull
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleInformation.py
+ * @skipline #//initializationfull
+ * @until #//initializationfull
+ *
+ * @param key A string containing the key of the XdmfInformation to create.
+ * @param value A string containing the value of the XdmfInformation to
+ * create.
+ *
+ * @return Constructed XdmfInformation
+ */
+ static shared_ptr<XdmfInformation> New(const std::string & key,
+ const std::string & value);
+
+ virtual ~XdmfInformation();
+
+ LOKI_DEFINE_VISITABLE(XdmfInformation, XdmfItem)
+ XDMF_CHILDREN(XdmfInformation, XdmfArray, Array, Name)
+ static const std::string ItemTag;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ virtual std::string getItemTag() const;
+
+ /**
+ * Get the key for this information item.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfInformation.cpp
+ * @skipline //#initializationfull
+ * @until //#initializationfull
+ * @skipline //#getKey
+ * @until //#getKey
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleInformation.py
+ * @skipline #//initializationfull
+ * @until #//initializationfull
+ * @skipline #//getKey
+ * @until #//getKey
+ *
+ * @return A string containing the key.
+ */
+ std::string getKey() const;
+
+ /**
+ * Get the value for this information item.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfInformation.cpp
+ * @skipline //#initializationfull
+ * @until //#initializationfull
+ * @skipline //#getValue
+ * @until //#getValue
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleInformation.py
+ * @skipline #//initializationfull
+ * @until #//initializationfull
+ * @skipline #//getValue
+ * @until #//getValue
+ *
+ * @return A string containing the value.
+ */
+ std::string getValue() const;
+
+ using XdmfItem::insert;
+
+ /**
+ * Set the key for this information item.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfInformation.cpp
+ * @skipline //#initializationfull
+ * @until //#initializationfull
+ * @skipline //#setKey
+ * @until //#setKey
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleInformation.py
+ * @skipline #//initializationfull
+ * @until #//initializationfull
+ * @skipline #//setKey
+ * @until #//setKey
+ *
+ * @param key A string containing the key to set.
+ */
+ void setKey(const std::string & key);
+
+ /**
+ * Set the value for this information item.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfInformation.cpp
+ * @skipline //#initializationfull
+ * @until //#initializationfull
+ * @skipline //#setValue
+ * @until //#setValue
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleInformation.py
+ * @skipline #//initializationfull
+ * @until #//initializationfull
+ * @skipline #//setValue
+ * @until #//setValue
+ *
+ * @param value A string containing the value to set.
+ */
+ void setValue(const std::string & value);
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfInformation(XdmfInformation &);
+
+protected:
+
+ XdmfInformation(const std::string & key = "",
+ const std::string & value = "");
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfInformation(const XdmfInformation &); // Not implemented.
+ void operator=(const XdmfInformation &); // Not implemented.
+
+ std::string mKey;
+ std::string mValue;
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+#ifndef XDMFINFORMATIONCDEFINE
+#define XDMFINFORMATIONCDEFINE
+struct XDMFINFORMATION; // Simply as a typedef to ensure correct typing
+typedef struct XDMFINFORMATION XDMFINFORMATION;
+#endif
+
+XDMFCORE_EXPORT XDMFINFORMATION * XdmfInformationNew(char * key, char * value);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfInformationGetArray(XDMFINFORMATION * information, unsigned int index);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfInformationGetArrayByName(XDMFINFORMATION * information, char * name);
+
+XDMFCORE_EXPORT char * XdmfInformationGetKey(XDMFINFORMATION * information);
+
+XDMFCORE_EXPORT unsigned int XdmfInformationGetNumberArrays(XDMFINFORMATION * information);
+
+XDMFCORE_EXPORT char * XdmfInformationGetValue(XDMFINFORMATION * information);
+
+XDMFCORE_EXPORT void XdmfInformationInsertArray(XDMFINFORMATION * information, XDMFARRAY * array, int transferOwnership);
+
+XDMFCORE_EXPORT void XdmfInformationRemoveArray(XDMFINFORMATION * information, unsigned int index);
+
+XDMFCORE_EXPORT void XdmfInformationRemoveArrayByName(XDMFINFORMATION * information, char * name);
+
+XDMFCORE_EXPORT void XdmfInformationSetKey(XDMFINFORMATION * information, char * key, int * status);
+
+XDMFCORE_EXPORT void XdmfInformationSetValue(XDMFINFORMATION * information, char * value, int * status);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfInformation, XDMFINFORMATION, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFINFORMATION_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfItem.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfInformation.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfVisitor.hpp"
+#include "XdmfError.hpp"
+#include "string.h"
+
+XDMF_CHILDREN_IMPLEMENTATION(XdmfItem, XdmfInformation, Information, Key)
+
+XdmfItem::XdmfItem() :
+ mIsChanged(true)
+{
+}
+
+XdmfItem::XdmfItem(const XdmfItem &refItem) :
+ mInformations(refItem.mInformations),
+ mIsChanged(true)
+{
+}
+
+XdmfItem::~XdmfItem()
+{
+}
+
+bool
+XdmfItem::getIsChanged()
+{
+ return mIsChanged;
+}
+
+void
+XdmfItem::setIsChanged(bool status)
+{
+ // No change if status is the same
+ if (mIsChanged != status)
+ {
+ mIsChanged = status;
+ // If it was changed all parents should be alerted
+ if (status)
+ {
+ for (std::set<XdmfItem *>::iterator iter = mParents.begin();
+ iter != mParents.end();
+ ++iter)
+ {
+ (*iter)->setIsChanged(status);
+ }
+ }
+ }
+}
+
+void
+XdmfItem::populateItem(const std::map<std::string, std::string> &,
+ const std::vector<shared_ptr<XdmfItem > > & childItems,
+ const XdmfCoreReader * const)
+{
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfInformation> information =
+ shared_dynamic_cast<XdmfInformation>(*iter)) {
+ this->insert(information);
+ }
+ }
+}
+
+void
+XdmfItem::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ for (unsigned int i = 0; i < mInformations.size(); ++i)
+ {
+ mInformations[i]->accept(visitor);
+ }
+}
+
+// C Wrappers
+
+void XdmfItemAccept(XDMFITEM * item, XDMFVISITOR * visitor, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ shared_ptr<XdmfVisitor> visitPointer((XdmfVisitor *)visitor, XdmfNullDeleter());
+ ((XdmfItem *)(item))->accept(visitPointer);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfItemFree(void * item)
+{
+ if (item != NULL) {
+ delete ((XdmfItem *)item);
+ item = NULL;
+ }
+}
+
+XDMFINFORMATION * XdmfItemGetInformation(XDMFITEM * item, unsigned int index)
+{
+ return (XDMFINFORMATION *)((void *)(((XdmfItem *)(item))->getInformation(index).get()));
+}
+
+XDMFINFORMATION * XdmfItemGetInformationByKey(XDMFITEM * item, char * key)
+{
+ return (XDMFINFORMATION *)((void *)(((XdmfItem *)(item))->getInformation(key).get()));
+}
+
+unsigned int XdmfItemGetNumberInformations(XDMFITEM * item)
+{
+ return ((XdmfItem *)(item))->getNumberInformations();
+}
+
+void XdmfItemInsertInformation(XDMFITEM * item, XDMFINFORMATION * information, int passControl)
+{
+ if (passControl == 0) {
+ ((XdmfItem *)(item))->insert(shared_ptr<XdmfInformation>((XdmfInformation *)information, XdmfNullDeleter()));
+ }
+ else {
+ ((XdmfItem *)(item))->insert(shared_ptr<XdmfInformation>((XdmfInformation *)information));
+ }
+}
+
+void XdmfItemRemoveInformation(XDMFITEM * item, unsigned int index)
+{
+ ((XdmfItem *)(item))->removeInformation(index);
+}
+
+void XdmfItemRemoveInformationByKey(XDMFITEM * item, char * key)
+{
+ ((XdmfItem *)(item))->removeInformation(std::string(key));
+}
+
+char * XdmfItemGetItemTag(XDMFITEM * item)
+{
+ char * returnPointer = strdup(((XdmfItem *)(item))->getItemTag().c_str());
+ return returnPointer;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfItem.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFITEM_HPP_
+#define XDMFITEM_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfVisitor.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfCoreReader;
+class XdmfInformation;
+class XdmfVisitor;
+
+// Includes
+#include <loki/Visitor.h>
+#include "vtk_libxml2.h"
+#include VTKLIBXML2_HEADER(xmlexports.h)
+#include VTKLIBXML2_HEADER(tree.h)
+#include VTKLIBXML2_HEADER(uri.h)
+#include VTKLIBXML2_HEADER(xpointer.h)
+#include VTKLIBXML2_HEADER(xmlreader.h)
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+#include "XdmfSharedPtr.hpp"
+
+// Macro that allows children XdmfItems to be attached to a parent XdmfItem.
+// -- For Header File
+#define XDMF_CHILDREN(ParentClass, ChildClass, ChildName, SearchName) \
+ \
+public: \
+ \
+ /** Get a ChildClass attached to this item by index.<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ unsigned int getIndex = 0;<br>
+ shared_ptr<XdmfInformation> exampleChild = exampleItem->getInformation(getIndex);<br>
+ Python<br>
+ '''<br>
+ Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ '''<br>
+ getIndex = 0<br>
+ exampleChild = exampleItem.getInformation(getIndex)<br>
+ @return requested ChildClass. If no ChildClass##s exist at the index,
+ a NULL pointer is returned.
+ */ \
+ virtual shared_ptr<ChildClass> \
+ get##ChildName(const unsigned int index); \
+ \
+ /** Get a ChildClass attached to this item by index (const version).<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ unsigned int getIndex = 0;<br>
+ shared_ptr<const XdmfInformation> exampleChildConst = exampleItem->getInformation(getIndex);<br>
+ Python: does not support a constant version of this function
+ @param index of the ChildClass to retrieve.
+ @return requested ChildClass. If no ChildClass##s exist at the index, a
+ NULL pointer is returned.
+ */ \
+ virtual shared_ptr<const ChildClass> \
+ get##ChildName(const unsigned int index) const; \
+ \
+ /** Get a ChildClass attached to this item by SearchName.<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ std::string findingInfo = "Find this";<br>
+ shared_ptr<XdmfInformation> exampleStringChild = exampleItem->getInformation(findingInfo);<br>
+ Python<br>
+ '''<br>
+ Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ '''<br>
+ findingInfo = "Find this"<br>
+ exampleStringChild = exampleItem.getInformation(findingInfo)<br>
+ @param SearchName of the ChildClass to retrieve.
+ @return requested ChildClass. If no ChildClass##s are found with the
+ correct SearchName, a NULL pointer is returned.
+ */ \
+ virtual shared_ptr<ChildClass> \
+ get##ChildName(const std::string & SearchName); \
+ \
+ /** Get a ChildClass attached to this item by SearchName (const version).<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ std::string findingInfo = "Find this";<br>
+ shared_ptr<const XdmfInformation> exampleStringChildConst = exampleItem->getInformation(findingInfo);<br>
+ Python: does not support a constant version of this function
+ @param SearchName of the ChildClass to retrieve.
+ @return requested ChildClass If no ChildClass##s are found with the
+ correct SearchName, a NULL pointer is returned.
+ */ \
+ virtual shared_ptr<const ChildClass> \
+ get##ChildName(const std::string & SearchName) const; \
+ \
+ /** Get the number of ChildClass##s attached to this item.<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ unsigned int exampleSize = exampleItem->getNumberInformations();<br>
+ Python<br>
+ '''<br>
+ Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ '''<br>
+ exampleSize = exampleItem.getNumberInformations()<br>
+ @return number of ChildClass##s attached to this item.
+ */ \
+ virtual unsigned int getNumber##ChildName##s() const; \
+ \
+ /** Insert a ChildClass into to this item.<br>
+ Example of use:<br>
+ C++<br>
+ shared_ptr<XdmfInformation> exampleItem = XdmfInformation::New("Parent", "This is a parent information");<br>
+ shared_ptr<XdmfInformation> addChild = XdmfInformation::New("Child", "This is a child information");<br>
+ exampleItem->insert(addChild);<br>
+ Python<br>
+ exampleItem = XdmfInformation.New("Parent", "This is a parent information")<br>
+ addChild = XdmfInformation.New("Child", "This is a child information")<br>
+ exampleItem.insert(addChild)<br>
+ @param ChildName to attach to this item.
+ */ \
+ virtual void insert(const shared_ptr<ChildClass> ChildName); \
+ \
+ /** Remove a ChildClass from this item by index. If no object exists
+ at the index, nothing is removed.<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ unsigned int removeIndex = 0;<br>
+ exampleItem->removeInformation(removeIndex);<br>
+ Python<br>
+ '''<br>
+ Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ '''<br>
+ removeIndex = 0<br>
+ exampleItem.removeInformation(removeIndex)
+ @param index of the ChildClass to remove.
+ */ \
+ virtual void remove##ChildName(const unsigned int index); \
+ \
+ /** Remove a ChildClass from this item by SearchName. If no ChildClass##s
+ have the correct SearchName, nothing is removed.<br>
+ Example of use:<br>
+ C++<br>
+ //Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ //Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ std::string removeInfo = "Remove this";<br>
+ exampleItem->removeInformation(removeInfo);<br>
+ Python<br>
+ '''<br>
+ Assume that exampleItem is a shared pointer to the ParentClass object<br>
+ Using an XdmfInformation as an example because all XdmfItems have XdmfInformation as a child class<br>
+ '''<br>
+ removeInfo = "Remove this"<br>
+ exampleItem.removeInformation(removeInfo)<br>
+ @param SearchName of the ChildClass to remove.
+ */ \
+ virtual void remove##ChildName(const std::string & SearchName); \
+ \
+protected : \
+ \
+ std::vector<shared_ptr<ChildClass> > m##ChildName##s; \
+ \
+public :
+
+// Macro that allows children XdmfItems to be attached to a parent XdmfItem.
+// -- For Implementation File
+#define XDMF_CHILDREN_IMPLEMENTATION(ParentClass, \
+ ChildClass, \
+ ChildName, \
+ SearchName) \
+ \
+ shared_ptr<ChildClass> \
+ ParentClass::get##ChildName(const unsigned int index) \
+ { \
+ return boost::const_pointer_cast<ChildClass> \
+ (static_cast<const ParentClass &>(*this).get##ChildName(index)); \
+ } \
+ \
+ shared_ptr<const ChildClass> \
+ ParentClass::get##ChildName(const unsigned int index) const \
+ { \
+ if(index < m##ChildName##s.size()) { \
+ return m##ChildName##s[index]; \
+ } \
+ return shared_ptr<ChildClass>(); \
+ } \
+ \
+ shared_ptr<ChildClass> \
+ ParentClass::get##ChildName(const std::string & SearchName) \
+ { \
+ return boost::const_pointer_cast<ChildClass> \
+ (static_cast<const ParentClass &>(*this).get##ChildName(SearchName)); \
+ } \
+ \
+ shared_ptr<const ChildClass> \
+ ParentClass::get##ChildName(const std::string & SearchName) const \
+ { \
+ for(std::vector<shared_ptr<ChildClass> >::const_iterator iter = \
+ m##ChildName##s.begin(); \
+ iter != m##ChildName##s.end(); \
+ ++iter) { \
+ if((*iter)->get##SearchName().compare(SearchName) == 0) { \
+ return *iter; \
+ } \
+ } \
+ return shared_ptr<ChildClass>(); \
+ } \
+ \
+ unsigned int \
+ ParentClass::getNumber##ChildName##s() const \
+ { \
+ return m##ChildName##s.size(); \
+ } \
+ \
+ void \
+ ParentClass::insert(const shared_ptr<ChildClass> ChildName) \
+ { \
+ m##ChildName##s.push_back(ChildName); \
+ this->setIsChanged(true); \
+ } \
+ \
+ void \
+ ParentClass::remove##ChildName(const unsigned int index) \
+ { \
+ if(index < m##ChildName##s.size()) { \
+ m##ChildName##s.erase(m##ChildName##s.begin() + index); \
+ } \
+ this->setIsChanged(true); \
+ } \
+ \
+ void \
+ ParentClass::remove##ChildName(const std::string & SearchName) \
+ { \
+ for(std::vector<shared_ptr<ChildClass> >::iterator iter = \
+ m##ChildName##s.begin(); \
+ iter != m##ChildName##s.end(); \
+ ++iter) { \
+ if((*iter)->get##SearchName().compare(SearchName) == 0) { \
+ m##ChildName##s.erase(iter); \
+ return; \
+ } \
+ } \
+ this->setIsChanged(true); \
+ }
+
+/**
+ * @brief Base class of any object that is able to be added to an Xdmf
+ * structure.
+ *
+ * XdmfItem is an abstract base class. An XdmfItem is a structure that
+ * can be visited and traversed by an XdmfVisitor and have its
+ * contents written to an Xdmf file.
+ */
+class XDMFCORE_EXPORT XdmfItem : public Loki::BaseVisitable<void> {
+
+public:
+
+ virtual ~XdmfItem() = 0;
+
+ LOKI_DEFINE_VISITABLE_BASE()
+ XDMF_CHILDREN(XdmfItem, XdmfInformation, Information, Key)
+ friend class XdmfCoreReader;
+ friend class XdmfWriter;
+ friend class XdmfHeavyDataWriter;
+ friend class XdmfHDF5Writer;
+
+ /**
+ * Get the tag for this item. This is equivalent to tags in XML
+ * parlance.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfItem.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getItemTag
+ * @until //#getItemTag
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleItem.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getItemTag
+ * @until #//getItemTag
+ *
+ * @return The tag for this XdmfItem.
+ */
+ virtual std::string getItemTag() const = 0;
+
+ /**
+ * Get the key/value property pairs for this item. These are
+ * equivalent to attributes in XML parlance.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfItem.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getItemProperties
+ * @until //#getItemProperties
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleItem.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getItemProperties
+ * @until #//getItemProperties
+ *
+ * @return A map of key/value properties associated with this XdmfItem.
+ */
+ virtual std::map<std::string, std::string> getItemProperties() const = 0;
+
+ /**
+ * Traverse this item by passing the visitor to child items.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfItem.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#traverse
+ * @until //#traverse
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleItem.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//traverse
+ * @until #//traverse
+ *
+ * @param visitor The visitor to pass to child items.
+ */
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfItem(const XdmfItem &);
+
+protected:
+
+ XdmfItem();
+
+ /**
+ * Populates an item using a map of key/value property pairs and a
+ * vector of its child items. This is used to support generic
+ * reading of XdmfItems from disk.
+ *
+ * @param itemProperties a map of key/value properties associated with
+ * this item.
+ * @param childItems a vector of child items to be added to this item.
+ * @param reader the current XdmfCoreReader being used to populate Xdmf
+ * structures.
+ */
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem > > & childItems,
+ const XdmfCoreReader * const reader);
+
+ bool
+ getIsChanged();
+
+ void
+ setIsChanged(bool status);
+
+ std::set<XdmfItem *> mParents;
+
+ bool mIsChanged;
+
+private:
+
+// XdmfItem(const XdmfItem &); // It is implemented for C wrappers.
+ void operator=(const XdmfItem &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFITEM; // Simply as a typedef to ensure correct typing
+typedef struct XDMFITEM XDMFITEM;
+
+#ifndef XDMFINFORMATIONCDEFINE
+#define XDMFINFORMATIONCDEFINE
+struct XDMFINFORMATION; // Simply as a typedef to ensure correct typing
+typedef struct XDMFINFORMATION XDMFINFORMATION;
+#endif
+
+XDMFCORE_EXPORT void XdmfItemAccept(XDMFITEM * item, XDMFVISITOR * visitor, int * status);
+
+XDMFCORE_EXPORT void XdmfItemFree(void * item);
+
+XDMFCORE_EXPORT XDMFINFORMATION * XdmfItemGetInformation(XDMFITEM * item, unsigned int index);
+
+XDMFCORE_EXPORT XDMFINFORMATION * XdmfItemGetInformationByKey(XDMFITEM * item, char * key);
+
+XDMFCORE_EXPORT unsigned int XdmfItemGetNumberInformations(XDMFITEM * item);
+
+XDMFCORE_EXPORT void XdmfItemInsertInformation(XDMFITEM * item, XDMFINFORMATION * information, int passControl);
+
+XDMFCORE_EXPORT void XdmfItemRemoveInformation(XDMFITEM * item, unsigned int index);
+
+XDMFCORE_EXPORT void XdmfItemRemoveInformationByKey(XDMFITEM * item, char * key);
+
+XDMFCORE_EXPORT char * XdmfItemGetItemTag(XDMFITEM * item);
+
+#define XDMF_ITEM_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT void ClassName##Accept ( CClassName * item, XDMFVISITOR * visitor, int * status); \
+Level##_EXPORT CClassName * ClassName##Cast ( XDMFITEM * item); \
+Level##_EXPORT void ClassName##Free(void * item); \
+Level##_EXPORT XDMFINFORMATION * ClassName##GetInformation( CClassName * item, unsigned int index); \
+Level##_EXPORT XDMFINFORMATION * ClassName##GetInformationByKey( CClassName * item, char * key); \
+Level##_EXPORT unsigned int ClassName##GetNumberInformations( CClassName * item); \
+Level##_EXPORT void ClassName##InsertInformation( CClassName * item, XDMFINFORMATION * information, int passControl); \
+Level##_EXPORT void ClassName##RemoveInformation( CClassName * item, unsigned int index); \
+Level##_EXPORT void ClassName##RemoveInformationByKey( CClassName * item, char * key); \
+Level##_EXPORT char * ClassName##GetItemTag( CClassName * item);
+
+
+#define XDMF_ITEM_C_CHILD_WRAPPER(ClassName, CClassName) \
+void ClassName##Accept( CClassName * item, XDMFVISITOR * visitor, int * status) \
+{ \
+ XdmfItemAccept(((XDMFITEM *)item), visitor, status); \
+} \
+ \
+void ClassName##Free(void * item) \
+{ \
+ XdmfItemFree(item); \
+} \
+ \
+XDMFINFORMATION * ClassName##GetInformation( CClassName * item, unsigned int index) \
+{ \
+ return XdmfItemGetInformation(((XDMFITEM *)item), index); \
+} \
+ \
+XDMFINFORMATION * ClassName##GetInformationByKey( CClassName * item, char * key) \
+{ \
+ return XdmfItemGetInformationByKey(((XDMFITEM *)item), key); \
+} \
+ \
+unsigned int ClassName##GetNumberInformations( CClassName * item) \
+{ \
+ return XdmfItemGetNumberInformations(((XDMFITEM *)item)); \
+} \
+ \
+void ClassName##InsertInformation( CClassName * item, XDMFINFORMATION * information, int passControl) \
+{ \
+ XdmfItemInsertInformation(((XDMFITEM *)item), information, passControl); \
+} \
+ \
+void ClassName##RemoveInformation( CClassName * item, unsigned int index) \
+{ \
+ XdmfItemRemoveInformation(((XDMFITEM *)item), index); \
+} \
+ \
+void ClassName##RemoveInformationByKey( CClassName * item, char * key) \
+{ \
+ XdmfItemRemoveInformationByKey(((XDMFITEM *)item), key); \
+} \
+ \
+char * ClassName##GetItemTag( CClassName * item) \
+{ \
+ return XdmfItemGetItemTag(((XDMFITEM *)item)); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFITEM_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfItemProperty.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfItemProperty.hpp"
+#include <boost/assign.hpp>
+
+const std::map<const char, const char> XdmfItemProperty::UpperConversionMap =
+ boost::assign::map_list_of ('a', 'A')
+ ('b', 'B')
+ ('c', 'C')
+ ('d', 'D')
+ ('e', 'E')
+ ('f', 'F')
+ ('g', 'G')
+ ('h', 'H')
+ ('i', 'I')
+ ('j', 'J')
+ ('k', 'K')
+ ('l', 'L')
+ ('m', 'M')
+ ('n', 'N')
+ ('o', 'O')
+ ('p', 'P')
+ ('q', 'Q')
+ ('r', 'R')
+ ('s', 'S')
+ ('t', 'T')
+ ('u', 'U')
+ ('v', 'V')
+ ('w', 'W')
+ ('x', 'X')
+ ('y', 'Y')
+ ('z', 'Z');
+
+// Using this method because ANSI and std transform aren't guarenteed
+std::string
+XdmfItemProperty::ConvertToUpper(const std::string & converted)
+{
+ std::string returnstring;
+ returnstring.resize(converted.size());
+ std::map<const char, const char>::const_iterator characterConversion;
+ for (unsigned int i = 0; i < converted.size(); ++i)
+ {
+ characterConversion = UpperConversionMap.find(converted[i]);
+ if (characterConversion != UpperConversionMap.end())
+ {
+ returnstring[i] = characterConversion->second;
+ }
+ else
+ {
+ returnstring[i] = converted[i];
+ }
+ }
+ return returnstring;
+}
+
+XdmfItemProperty::XdmfItemProperty()
+{
+}
+
+XdmfItemProperty::~XdmfItemProperty()
+{
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfItemProperty.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFITEMPROPERTY_HPP_
+#define XDMFITEMPROPERTY_HPP_
+
+#ifdef __cplusplus
+
+// Includes
+#include <map>
+#include <string>
+#include "XdmfCore.hpp"
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief A property attached to an XdmfItem.
+ *
+ * XdmfItems can have zero or more properties attached to them that
+ * describe a specific characteristic of that item. For instance,
+ * XdmfAttributes have both center and type properties.
+ *
+ * This is an abstract base class to facilitate reading and writing of
+ * properties in a generic way.
+ */
+
+class XDMFCORE_EXPORT XdmfItemProperty {
+
+public:
+
+ virtual ~XdmfItemProperty() = 0;
+
+ /**
+ * Retrieve the key/value pairs that this XdmfItemProperty contains by
+ * inserting into the passed map.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfItemProperty.cpp
+ * @skipline //#getProperties
+ * @until //#getProperties
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleItemProperty.py
+ * @skipline #//getProperties
+ * @until #//getProperties
+ *
+ * @param collectedProperties A map to insert name / value pairs into.
+ */
+ virtual void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const = 0;
+
+protected:
+
+ XdmfItemProperty();
+
+ static std::string ConvertToUpper(const std::string & converted);
+
+ static const std::map<const char, const char> UpperConversionMap;
+
+private:
+
+ XdmfItemProperty(const XdmfItemProperty &); // Not implemented.
+ void operator=(const XdmfItemProperty &); // Not implemented.
+
+};
+
+#endif
+
+#endif /* XDMFITEMPROPERTY_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* Xdmf */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfPlaceholder.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2014 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <vtk_hdf5.h>
+#include <sstream>
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfError.hpp"
+#include "XdmfHeavyDataDescription.hpp"
+#include "XdmfPlaceholder.hpp"
+#include "XdmfSystemUtils.hpp"
+#include "string.h"
+
+shared_ptr<XdmfPlaceholder>
+XdmfPlaceholder::New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions)
+{
+ shared_ptr<XdmfPlaceholder>
+ p(new XdmfPlaceholder(filePath,
+ type,
+ start,
+ stride,
+ dimensions,
+ dataspaceDimensions));
+ return p;
+}
+
+XdmfPlaceholder::XdmfPlaceholder(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions) :
+ XdmfHeavyDataController(filePath,
+ type,
+ start,
+ stride,
+ dimensions,
+ dataspaceDimensions)
+{
+}
+
+XdmfPlaceholder::XdmfPlaceholder(const XdmfPlaceholder & refController):
+ XdmfHeavyDataController(refController)
+{
+}
+
+XdmfPlaceholder::~XdmfPlaceholder()
+{
+}
+
+shared_ptr<XdmfHeavyDataController>
+XdmfPlaceholder::createSubController(const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions)
+{
+ return XdmfPlaceholder::New(mFilePath,
+ mType,
+ starts,
+ strides,
+ dimensions,
+ mDataspaceDimensions);
+}
+
+std::string
+XdmfPlaceholder::getDescriptor() const
+{
+ return "";
+}
+
+shared_ptr<XdmfHeavyDataDescription>
+XdmfPlaceholder::getHeavyDataDescription()
+{
+ static shared_ptr<XdmfHeavyDataDescription> p = shared_ptr<XdmfHeavyDataDescription>();
+ return p;
+}
+
+std::string
+XdmfPlaceholder::getName() const
+{
+ return "Placeholder";
+}
+
+void
+XdmfPlaceholder::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties["Format"] = this->getName();
+}
+
+void
+XdmfPlaceholder::read(XdmfArray * const array)
+{
+ array->initialize(this->getType(), this->getDimensions());
+}
+
+// C Wrappers
+
+XDMFPLACEHOLDER * XdmfPlaceholderNew(char * hdf5FilePath,
+ int type,
+ unsigned int * start,
+ unsigned int * stride,
+ unsigned int * dimensions,
+ unsigned int * dataspaceDimensions,
+ unsigned int numDims,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfPlaceholder> generatedController = XdmfPlaceholder::New(std::string(hdf5FilePath), buildType, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFPLACEHOLDER *)((void *)(new XdmfPlaceholder(*generatedController.get())));
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfPlaceholder> generatedController = XdmfPlaceholder::New(std::string(hdf5FilePath), buildType, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFPLACEHOLDER *)((void *)(new XdmfPlaceholder(*generatedController.get())));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_HEAVYCONTROLLER_C_CHILD_WRAPPER(XdmfPlaceholder, XDMFPLACEHOLDER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfPlaceholder.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFPLACEHOLDER_HPP_
+#define XDMFPLACEHOLDER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataController.hpp"
+
+#ifdef __cplusplus
+
+#include <map>
+
+/**
+ * @brief Couples an XdmfArray with an array structure.
+ *
+ * Takes the place of a heavy data set. Allows an array to define
+ * its structure without having to have an associated dataset.
+ */
+class XDMFCORE_EXPORT XdmfPlaceholder : public XdmfHeavyDataController {
+
+public:
+
+ virtual ~XdmfPlaceholder();
+
+ /**
+ * Create a new placeholder to define array structure.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfPlaceholder.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExamplePlaceholder.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param filePath The location of the file the data set resides in.
+ * @param type The data type of the dataset to read.
+ * @param start The offset of the starting element in each
+ * dimension in the data set.
+ * @param stride The number of elements to move in each
+ * dimension from the data set.
+ * @param dimensions The number of elements to select in each
+ * dimension from the data set.
+ * (size in each dimension)
+ * @param dataspaceDimensions The number of elements in the entire
+ * data set (may be larger than
+ * dimensions if using hyperslabs).
+ *
+ * @return New Placeholder.
+ */
+ static shared_ptr<XdmfPlaceholder>
+ New(const std::string & FilePath,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions);
+
+ virtual std::string getDescriptor() const;
+
+ virtual std::string getName() const;
+
+ virtual void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+ virtual void read(XdmfArray * const array);
+
+ XdmfPlaceholder(const XdmfPlaceholder &);
+
+protected:
+
+ XdmfPlaceholder(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> type,
+ const std::vector<unsigned int> & start,
+ const std::vector<unsigned int> & stride,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaceDimensions);
+
+ shared_ptr<XdmfHeavyDataController>
+ createSubController(const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions);
+
+ virtual shared_ptr<XdmfHeavyDataDescription>
+ getHeavyDataDescription();
+
+ void read(XdmfArray * const array, const int fapl);
+
+private:
+
+ void operator=(const XdmfPlaceholder &); // Not implemented.
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct XDMFPLACEHOLDER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFPLACEHOLDER XDMFPLACEHOLDER;
+
+XDMFCORE_EXPORT XDMFPLACEHOLDER * XdmfPlaceholderNew(char * hdf5FilePath,
+ int type,
+ unsigned int * start,
+ unsigned int * stride,
+ unsigned int * dimensions,
+ unsigned int * dataspaceDimensions,
+ unsigned int numDims,
+ int * status);
+
+// C Wrappers for parent classes are generated by macros
+
+/*
+XDMFCORE_EXPORT unsigned int * XdmfPlaceholderGetDataspaceDimensions(XDMFPLACEHOLDER * controller);
+
+XDMFCORE_EXPORT unsigned int * XdmfPlaceholderGetStart(XDMFPLACEHOLDER * controller);
+
+XDMFCORE_EXPORT unsigned int * XdmfPlaceholderGetStride(XDMFPLACEHOLDER * controller);
+*/
+
+XDMF_HEAVYCONTROLLER_C_CHILD_DECLARE(XdmfPlaceholder, XDMFPLACEHOLDER, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFPLACEHOLDER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSharedPtr.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFSHAREDPTR_HPP_
+#define XDMFSHAREDPTR_HPP_
+
+#ifdef __cplusplus
+
+#include "XdmfCoreConfig.hpp"
+#include <boost/shared_ptr.hpp>
+
+using boost::shared_ptr;
+
+#ifdef HAVE_BOOST_SHARED_DYNAMIC_CAST
+
+using boost::shared_dynamic_cast;
+
+#else
+
+template <typename T, typename U>
+shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
+{
+ typedef typename shared_ptr<T>::element_type E;
+ E * p = dynamic_cast< E* >( r.get() );
+ return p? shared_ptr<T>( r, p ): shared_ptr<T>();
+}
+
+#endif /* HAVE_BOOST_SHARED_DYNAMIC_CAST */
+
+// Used by C wrappers to prevent shared pointers from prematurely deleting objects
+// Normally this would be completely against the point of shared pointers,
+// but the C wrapping requires that objects be seperated from the shared pointers.
+struct XdmfNullDeleter
+{
+template<typename T>
+void operator()(T*) {}
+};
+
+#endif
+
+#endif /* XDMFSHAREDPTR_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSparseMatrix.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <iostream>
+#include <sstream>
+#include "string.h"
+#include "XdmfSparseMatrix.hpp"
+#include "XdmfError.hpp"
+
+shared_ptr<XdmfSparseMatrix>
+XdmfSparseMatrix::New(const unsigned int numberRows,
+ const unsigned int numberColumns)
+{
+ shared_ptr<XdmfSparseMatrix> p(new XdmfSparseMatrix(numberRows,
+ numberColumns));
+ return p;
+}
+
+XdmfSparseMatrix::XdmfSparseMatrix(const unsigned int numberRows,
+ const unsigned int numberColumns) :
+ mColumnIndex(XdmfArray::New()),
+ mName(""),
+ mNumberColumns(numberColumns),
+ mNumberRows(numberRows),
+ mRowPointer(XdmfArray::New()),
+ mValues(XdmfArray::New())
+{
+ mRowPointer->resize<unsigned int>(mNumberRows + 1, 0);
+}
+
+XdmfSparseMatrix::XdmfSparseMatrix(XdmfSparseMatrix & matrixRef) :
+ XdmfItem(matrixRef),
+ mColumnIndex(matrixRef.getColumnIndex()),
+ mName(matrixRef.getName()),
+ mNumberColumns(matrixRef.getNumberColumns()),
+ mNumberRows(matrixRef.getNumberRows()),
+ mRowPointer(matrixRef.getRowPointer()),
+ mValues(matrixRef.getValues())
+{
+}
+
+XdmfSparseMatrix::~XdmfSparseMatrix()
+{
+}
+
+const std::string XdmfSparseMatrix::ItemTag = "SparseMatrix";
+
+shared_ptr<XdmfArray>
+XdmfSparseMatrix::getColumnIndex()
+{
+ return mColumnIndex;
+}
+
+std::map<std::string, std::string>
+XdmfSparseMatrix::getItemProperties() const
+{
+ std::map<std::string, std::string> sparseMatrixProperties;
+ sparseMatrixProperties.insert(std::make_pair("Name", mName));
+ std::stringstream numberRowsString;
+ numberRowsString << mNumberRows;
+ sparseMatrixProperties.insert(std::make_pair("NumberRows",
+ numberRowsString.str()));
+ std::stringstream numberColumnsString;
+ numberColumnsString << mNumberColumns;
+ sparseMatrixProperties.insert(std::make_pair("NumberColumns",
+ numberColumnsString.str()));
+ return sparseMatrixProperties;
+}
+
+std::string
+XdmfSparseMatrix::getItemTag() const
+{
+ return ItemTag;
+}
+
+std::string
+XdmfSparseMatrix::getName() const
+{
+ if (mName.c_str() == NULL) {
+ return "";
+ }
+ else {
+ return mName;
+ }
+}
+
+unsigned int
+XdmfSparseMatrix::getNumberColumns() const
+{
+ return mNumberColumns;
+}
+
+unsigned int
+XdmfSparseMatrix::getNumberRows() const
+{
+ return mNumberRows;
+}
+
+shared_ptr<XdmfArray>
+XdmfSparseMatrix::getRowPointer()
+{
+ return mRowPointer;
+}
+
+shared_ptr<XdmfArray>
+XdmfSparseMatrix::getValues()
+{
+ return mValues;
+}
+
+std::string
+XdmfSparseMatrix::getValuesString() const
+{
+
+ std::stringstream toReturn;
+ for(unsigned int i=0; i<mNumberRows; ++i) {
+ if (i + 1 < mNumberRows) {
+ if (mRowPointer->getValue<unsigned int>(i) > mRowPointer->getValue<unsigned int>(i+1)) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: getValuesString(), Sparse Matrix Row Pointer is not sorted.");
+ }
+ }
+ unsigned int index = 0;
+ for(unsigned int j=mRowPointer->getValue<unsigned int>(i);
+ j<mRowPointer->getValue<unsigned int>(i+1);
+ ++j) {
+ const unsigned int k = mColumnIndex->getValue<unsigned int>(j);
+ while(index++ < k) {
+ toReturn << "0.0, ";
+ }
+ toReturn << mValues->getValue<double>(j) << ", ";
+ }
+ while(index++ < mNumberColumns) {
+ toReturn << "0.0, ";
+ }
+ toReturn << std::endl;
+ }
+
+ return toReturn.str();
+
+}
+
+void
+XdmfSparseMatrix::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ XdmfItem::populateItem(itemProperties, childItems, reader);
+ std::map<std::string, std::string>::const_iterator name =
+ itemProperties.find("Name");
+ if(name != itemProperties.end()) {
+ mName = name->second;
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'Name' not found in itemProperties in "
+ "XdmfSparseMatrix::populateItem");
+ }
+ std::map<std::string, std::string>::const_iterator numberRows =
+ itemProperties.find("NumberRows");
+ if(numberRows != itemProperties.end()) {
+ mNumberRows = std::atoi(numberRows->second.c_str());
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'NumberRows' not found in itemProperties in "
+ "XdmfSparseMatrix::populateItem");
+ }
+ std::map<std::string, std::string>::const_iterator numberColumns =
+ itemProperties.find("NumberColumns");
+ if(numberColumns != itemProperties.end()) {
+ mNumberColumns = std::atoi(numberColumns->second.c_str());
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "'NumberColumns' not found in itemProperties in "
+ "XdmfSparseMatrix::populateItem");
+ }
+
+ std::vector<shared_ptr<XdmfArray> > arrayVector;
+ arrayVector.reserve(3);
+ for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
+ childItems.begin();
+ iter != childItems.end();
+ ++iter) {
+ if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
+ arrayVector.push_back(array);
+ }
+ }
+
+ if(arrayVector.size() < 3) {
+ // The three required arrays are for
+ // the row pointer, column index, and the contained values.
+ // Without these arrays the object can't be properly built.
+ XdmfError::message(XdmfError::FATAL,
+ "Expected 3 arrays attached to "
+ "XdmfSparseMatrix::populateItem");
+ }
+ mRowPointer = arrayVector[0];
+ mColumnIndex = arrayVector[1];
+ mValues = arrayVector[2];
+}
+
+void
+XdmfSparseMatrix::setColumnIndex(const shared_ptr<XdmfArray> columnIndex)
+{
+ mColumnIndex = columnIndex;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSparseMatrix::setName(const std::string & name)
+{
+ mName = name;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSparseMatrix::setRowPointer(const shared_ptr<XdmfArray> rowPointer)
+{
+ mRowPointer = rowPointer;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSparseMatrix::setValues(const shared_ptr<XdmfArray> values)
+{
+ mValues = values;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSparseMatrix::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+ mRowPointer->accept(visitor);
+ mColumnIndex->accept(visitor);
+ mValues->accept(visitor);
+}
+
+// C Wrappers
+
+XDMFSPARSEMATRIX * XdmfSparseMatrixNew(unsigned int numberRows, unsigned int numberColumns)
+{
+ try
+ {
+ shared_ptr<XdmfSparseMatrix> generatedMatrix = XdmfSparseMatrix::New(numberRows, numberColumns);
+ return (XDMFSPARSEMATRIX *)((void *)(new XdmfSparseMatrix(*generatedMatrix.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfSparseMatrix> generatedMatrix = XdmfSparseMatrix::New(numberRows, numberColumns);
+ return (XDMFSPARSEMATRIX *)((void *)(new XdmfSparseMatrix(*generatedMatrix.get())));
+ }
+}
+
+XDMFARRAY * XdmfSparseMatrixGetColumnIndex(XDMFSPARSEMATRIX * matrix, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return (XDMFARRAY *)((void *)(((XdmfSparseMatrix *)(matrix))->getColumnIndex().get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+char * XdmfSparseMatrixGetName(XDMFSPARSEMATRIX * matrix)
+{
+ try
+ {
+ char * returnPointer= strdup(((XdmfSparseMatrix *)(matrix))->getName().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer= strdup(((XdmfSparseMatrix *)(matrix))->getName().c_str());
+ return returnPointer;
+ }
+}
+
+unsigned int XdmfSparseMatrixGetNumberColumns(XDMFSPARSEMATRIX * matrix)
+{
+ return ((XdmfSparseMatrix *)matrix)->getNumberColumns();
+}
+
+unsigned int XdmfSparseMatrixGetNumberRows(XDMFSPARSEMATRIX * matrix)
+{
+ return ((XdmfSparseMatrix *)matrix)->getNumberRows();
+}
+
+XDMFARRAY * XdmfSparseMatrixGetRowPointer(XDMFSPARSEMATRIX * matrix, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return (XDMFARRAY *)((void *)(((XdmfSparseMatrix *)(matrix))->getRowPointer().get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFARRAY * XdmfSparseMatrixGetValues(XDMFSPARSEMATRIX * matrix, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return (XDMFARRAY *)((void *)(((XdmfSparseMatrix *)(matrix))->getValues().get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+char * XdmfSparseMatrixGetValuesString(XDMFSPARSEMATRIX * matrix, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ char * returnPointer = strdup(((XdmfSparseMatrix *)(matrix))->getValuesString().c_str());
+ return returnPointer;
+ }
+ catch (...)
+ {
+ char * returnPointer = strdup(((XdmfSparseMatrix *)(matrix))->getValuesString().c_str());
+ return returnPointer;
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+void XdmfSparseMatrixSetColumnIndex(XDMFSPARSEMATRIX * matrix, XDMFARRAY * columnIndex, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ if (passControl) {
+ ((XdmfSparseMatrix *)(matrix))->setColumnIndex(shared_ptr<XdmfArray>((XdmfArray *)columnIndex));
+ }
+ else {
+ ((XdmfSparseMatrix *)(matrix))->setColumnIndex(shared_ptr<XdmfArray>((XdmfArray *)columnIndex, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfSparseMatrixSetName(XDMFSPARSEMATRIX * matrix, char * name, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfSparseMatrix *)matrix)->setName(std::string(name));
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfSparseMatrixSetRowPointer(XDMFSPARSEMATRIX * matrix, XDMFARRAY * rowPointer, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ if (passControl) {
+ ((XdmfSparseMatrix *)(matrix))->setRowPointer(shared_ptr<XdmfArray>((XdmfArray *)rowPointer));
+ }
+ else {
+ ((XdmfSparseMatrix *)(matrix))->setRowPointer(shared_ptr<XdmfArray>((XdmfArray *)rowPointer, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfSparseMatrixSetValues(XDMFSPARSEMATRIX * matrix, XDMFARRAY * values, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ if (passControl) {
+ ((XdmfSparseMatrix *)(matrix))->setValues(shared_ptr<XdmfArray>((XdmfArray *)values));
+ }
+ else {
+ ((XdmfSparseMatrix *)(matrix))->setValues(shared_ptr<XdmfArray>((XdmfArray *)values, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfSparseMatrix, XDMFSPARSEMATRIX)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSparseMatrix.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFSPARSEMATRIX_HPP_
+#define XDMFSPARSEMATRIX_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfArray.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Sparse matrix implemented as compressed row storage.
+ *
+ * An XdmfSparseMatrix provides routines for interacting with a sparse
+ * matrix. It is stored internally in compressed row storage.
+ */
+class XDMFCORE_EXPORT XdmfSparseMatrix : public XdmfItem {
+
+public:
+
+ /**
+ * Create a new XdmfSparseMatrix.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param numberRows Number of rows in matrix.
+ * @param numberColumns Number of columns in matrix.
+ *
+ * @return Constructed XdmfSparseMatrix.
+ */
+ static shared_ptr<XdmfSparseMatrix> New(const unsigned int numberRows,
+ const unsigned int numberColumns);
+
+ virtual ~XdmfSparseMatrix();
+
+ LOKI_DEFINE_VISITABLE(XdmfSparseMatrix, XdmfItem)
+ static const std::string ItemTag;
+
+ /**
+ * Get the column index array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setColumnIndex
+ * @until //#setColumnIndex
+ * @skipline //#getColumnIndex
+ * @until //#getColumnIndex
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setColumnIndex
+ * @until #//setColumnIndex
+ * @skipline #//getColumnIndex
+ * @until #//getColumnIndex
+ *
+ * @return Array containing column indices for nonzero entries of
+ * matrix. This is the same size as values.
+ */
+ shared_ptr<XdmfArray> getColumnIndex();
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Get the name of the sparse matrix.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ * @skipline //#getName
+ * @until //#getName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ * @skipline #//getName
+ * @until #//getName
+ *
+ * @return A string containing the name of the sparse matrix.
+ */
+ std::string getName() const;
+
+ /**
+ * Get the number of columns in the sparse matrix.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setColumnIndex
+ * @until //#setColumnIndex
+ * @skipline //#getNumberColumns
+ * @until //#getNumberColumns
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setColumnIndex
+ * @until #//setColumnIndex
+ * @skipline #//getNumberColumns
+ * @until #//getNumberColumns
+ *
+ * @return The number of columns in the sparse matrix.
+ */
+ unsigned int getNumberColumns() const;
+
+ /**
+ * Get the number of rows in the sparse matrix.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setRowPointer
+ * @until //#setRowPointer
+ * @skipline //#getNumberRows
+ * @until //#getNumberRows
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setRowPointer
+ * @until #//setRowPointer
+ * @skipline #//getNumberRows
+ * @until #//getNumberRows
+ *
+ * @return The number of rows in the sparse matrix.
+ */
+ unsigned int getNumberRows() const;
+
+ /**
+ * Get the row pointer array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setRowPointer
+ * @until //#setRowPointer
+ * @skipline //#getRowPointer
+ * @until //#getRowPointer
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setRowPointer
+ * @until #//setRowPointer
+ * @skipline #//getRowPointer
+ * @until #//getRowPointer
+ *
+ * @return Array containing indices into column array for each
+ * row. This is the size of the number of rows in the matrix +
+ * 1. The last value is the number of nonzero entries in the matrix
+ */
+ shared_ptr<XdmfArray> getRowPointer();
+
+ /**
+ * Get the values array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setRowPointer
+ * @until //#setRowPointer
+ * @skipline //#setColumnIndex
+ * @until //#setColumnIndex
+ * @skipline //#setValues
+ * @until //#setValues
+ * @skipline //#getValues
+ * @until //#getValues
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setRowPointer
+ * @until #//setRowPointer
+ * @skipline #//setColumnIndex
+ * @until #//setColumnIndex
+ * @skipline #//setValues
+ * @until #//setValues
+ * @skipline #//getValues
+ * @until #//getValues
+ *
+ * @return Array containing values of nonzero entries of matrix.
+ */
+ shared_ptr<XdmfArray> getValues();
+
+ /**
+ * Get values as a string in two dimensional format.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setRowPointer
+ * @until //#setRowPointer
+ * @skipline //#setColumnIndex
+ * @until //#setColumnIndex
+ * @skipline //#setValues
+ * @until //#setValues
+ * @skipline //#getValuesString
+ * @until //#getValuesString
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setRowPointer
+ * @until #//setRowPointer
+ * @skipline #//setColumnIndex
+ * @until #//setColumnIndex
+ * @skipline #//setValues
+ * @until #//setValues
+ * @skipline #//getValuesString
+ * @until #//getValuesString
+ *
+ * @return Atring representation of matrix.
+ */
+ std::string getValuesString() const;
+
+ /**
+ * Set the column index array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setColumnIndex
+ * @until //#setColumnIndex
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setColumnIndex
+ * @until #//setColumnIndex
+ *
+ * @param columnIndex Array containing column indices for nonzero
+ * entries of matrix. This is the same size as values.
+ */
+ void setColumnIndex(const shared_ptr<XdmfArray> columnIndex);
+
+ /**
+ * Set the name of the sparse matrix.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setName
+ * @until //#setName
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setName
+ * @until #//setName
+ *
+ * @param name A string containing the name to set.
+ */
+ void setName(const std::string & name);
+
+ /**
+ * Set the row pointer array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setRowPointer
+ * @until //#setRowPointer
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setRowPointer
+ * @until #//setRowPointer
+ *
+ * @param rowPointer Array containing indices into column array for
+ * each row. This is the size of the number of rows in the matrix +
+ * 1. The last value is the number of nonzero entries in the matrix
+ */
+ void setRowPointer(const shared_ptr<XdmfArray> rowPointer);
+
+ /**
+ * Set the values array.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSparseMatrix.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#setRowPointer
+ * @until //#setRowPointer
+ * @skipline //#setColumnIndex
+ * @until //#setColumnIndex
+ * @skipline //#setValues
+ * @until //#setValues
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSparseMatrix.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//setRowPointer
+ * @until #//setRowPointer
+ * @skipline #//setColumnIndex
+ * @until #//setColumnIndex
+ * @skipline #//setValues
+ * @until #//setValues
+ *
+ * @param values Array containing values of nonzero entries of
+ * matrix.
+ */
+ void setValues(const shared_ptr<XdmfArray> values);
+
+ virtual void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfSparseMatrix(XdmfSparseMatrix &);
+
+protected:
+
+ XdmfSparseMatrix(const unsigned int numberRows,
+ const unsigned int numberColumns);
+
+ virtual void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+private:
+
+ XdmfSparseMatrix(const XdmfSparseMatrix &); // Not implemented.
+ void operator=(const XdmfSparseMatrix &); // Not implemented.
+
+ shared_ptr<XdmfArray> mColumnIndex;
+ std::string mName;
+ unsigned int mNumberColumns;
+ unsigned int mNumberRows;
+ shared_ptr<XdmfArray> mRowPointer;
+ shared_ptr<XdmfArray> mValues;
+};
+
+#ifdef _WIN32
+#endif
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFSPARSEMATRIX; // Simply as a typedef to ensure correct typing
+typedef struct XDMFSPARSEMATRIX XDMFSPARSEMATRIX;
+
+XDMFCORE_EXPORT XDMFSPARSEMATRIX * XdmfSparseMatrixNew(unsigned int numberRows, unsigned int numberColumns);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfSparseMatrixGetColumnIndex(XDMFSPARSEMATRIX * matrix, int * status);
+
+XDMFCORE_EXPORT char * XdmfSparseMatrixGetName(XDMFSPARSEMATRIX * matrix);
+
+XDMFCORE_EXPORT unsigned int XdmfSparseMatrixGetNumberColumns(XDMFSPARSEMATRIX * matrix);
+
+XDMFCORE_EXPORT unsigned int XdmfSparseMatrixGetNumberRows(XDMFSPARSEMATRIX * matrix);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfSparseMatrixGetRowPointer(XDMFSPARSEMATRIX * matrix, int * status);
+
+XDMFCORE_EXPORT XDMFARRAY * XdmfSparseMatrixGetValues(XDMFSPARSEMATRIX * matrix, int * status);
+
+XDMFCORE_EXPORT char * XdmfSparseMatrixGetValuesString(XDMFSPARSEMATRIX * matrix, int * status);
+
+XDMFCORE_EXPORT void XdmfSparseMatrixSetColumnIndex(XDMFSPARSEMATRIX * matrix, XDMFARRAY * columnIndex, int passControl, int * status);
+
+XDMFCORE_EXPORT void XdmfSparseMatrixSetName(XDMFSPARSEMATRIX * matrix, char * name, int * status);
+
+XDMFCORE_EXPORT void XdmfSparseMatrixSetRowPointer(XDMFSPARSEMATRIX * matrix, XDMFARRAY * rowPointer, int passControl, int * status);
+
+XDMFCORE_EXPORT void XdmfSparseMatrixSetValues(XDMFSPARSEMATRIX * matrix, XDMFARRAY * values, int passControl, int * status);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfSparseMatrix, XDMFSPARSEMATRIX, XDMFCORE)
+
+#define XDMF_SPARSEMATRIX_C_CHILD_DECLARE(ClassName, CClassName, Level) \
+ \
+Level##_EXPORT XDMFARRAY * ClassName##GetColumnIndex( CClassName * matrix, int * status); \
+Level##_EXPORT char * ClassName##GetName( CClassName * matrix); \
+Level##_EXPORT unsigned int ClassName##GetNumberColumns( CClassName * matrix); \
+Level##_EXPORT unsigned int ClassName##GetNumberRows( CClassName * matrix); \
+Level##_EXPORT XDMFARRAY * ClassName##GetRowPointer( CClassName * matrix, int * status); \
+Level##_EXPORT XDMFARRAY * ClassName##GetValues( CClassName * matrix, int * status); \
+Level##_EXPORT char * ClassName##GetValuesString( CClassName * matrix, int * status); \
+Level##_EXPORT void ClassName##SetColumnIndex( CClassName * matrix, XDMFARRAY * columnIndex, int passControl, int * status); \
+Level##_EXPORT void ClassName##SetName( CClassName * matrix, char * name, int * status); \
+Level##_EXPORT void ClassName##SetRowPointer( CClassName * matrix, XDMFARRAY * rowPointer, int passControl, int * status); \
+Level##_EXPORT void ClassName##SetValues( CClassName * matrix, XDMFARRAY * values, int passControl, int * status);
+
+#define XDMF_SPARSEMATRIX_C_CHILD_WRAPPER(ClassName, CClassName) \
+ \
+XDMFARRAY * ClassName##GetColumnIndex( CClassName * matrix, int * status) \
+{ \
+ return XdmfSparseMatrixGetColumnIndex((XDMFSPARSEMATRIX *)((void *)matrix), status); \
+} \
+ \
+char * ClassName##GetName( CClassName * matrix) \
+{ \
+ return XdmfSparseMatrixGetName((XDMFSPARSEMATRIX *)((void *)matrix)); \
+} \
+ \
+unsigned int ClassName##GetNumberColumns( CClassName * matrix) \
+{ \
+ return XdmfSparseMatrixGetNumberColumns((XDMFSPARSEMATRIX *)((void *)matrix)); \
+} \
+ \
+unsigned int ClassName##GetNumberRows( CClassName * matrix) \
+{ \
+ return XdmfSparseMatrixGetNumberRows((XDMFSPARSEMATRIX *)((void *)matrix)); \
+} \
+ \
+XDMFARRAY * ClassName##GetRowPointer( CClassName * matrix, int * status) \
+{ \
+ return XdmfSparseMatrixGetRowPointer((XDMFSPARSEMATRIX *)((void *)matrix), status); \
+} \
+ \
+XDMFARRAY * ClassName##GetValues( CClassName * matrix, int * status) \
+{ \
+ return XdmfSparseMatrixGetValues((XDMFSPARSEMATRIX *)((void *)matrix), status); \
+} \
+ \
+char * ClassName##GetValuesString( CClassName * matrix, int * status) \
+{ \
+ return XdmfSparseMatrixGetValuesString((XDMFSPARSEMATRIX *)((void *)matrix), status); \
+} \
+ \
+void ClassName##SetColumnIndex( CClassName * matrix, XDMFARRAY * columnIndex, int passControl, int * status) \
+{ \
+ XdmfSparseMatrixSetColumnIndex((XDMFSPARSEMATRIX *)((void *)matrix), columnIndex, passControl, status); \
+} \
+ \
+void ClassName##SetName( CClassName * matrix, char * name, int * status) \
+{ \
+ XdmfSparseMatrixSetName((XDMFSPARSEMATRIX *)((void *)matrix), name, status); \
+} \
+ \
+void ClassName##SetRowPointer( CClassName * matrix, XDMFARRAY * rowPointer, int passControl, int * status) \
+{ \
+ XdmfSparseMatrixSetRowPointer((XDMFSPARSEMATRIX *)((void *)matrix), rowPointer, passControl, status); \
+} \
+ \
+void ClassName##SetValues( CClassName * matrix, XDMFARRAY * values, int passControl, int * status) \
+{ \
+ XdmfSparseMatrixSetValues((XDMFSPARSEMATRIX *)((void *)matrix), values, passControl, status); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFSPARSEMATRIX_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSubset.cpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <numeric>
+#include <functional>
+#include <boost/tokenizer.hpp>
+#include "string.h"
+#include "XdmfArray.hpp"
+#include "XdmfError.hpp"
+#include "XdmfSubset.hpp"
+#include "XdmfWriter.hpp"
+
+XdmfSubset::XdmfSubset(shared_ptr<XdmfArray> referenceArray,
+ std::vector<unsigned int> & start,
+ std::vector<unsigned int> & stride,
+ std::vector<unsigned int> & dimensions) :
+ mParent(referenceArray),
+ mDimensions(dimensions),
+ mStart(start),
+ mStride(stride)
+{
+ if(!(mStart.size() == mStride.size() &&
+ mStride.size() == mDimensions.size())) {
+ XdmfError::message(XdmfError::FATAL,
+ "mStart, mStride, mDimensions must all be of equal "
+ "length in XdmfSubset constructor");
+ }
+}
+
+XdmfSubset::XdmfSubset(XdmfSubset & refSubset) :
+ XdmfArrayReference(refSubset),
+ mParent(refSubset.getReferenceArray()),
+ mDimensions(refSubset.getDimensions()),
+ mStart(refSubset.getStart()),
+ mStride(refSubset.getStride())
+{
+}
+
+XdmfSubset::~XdmfSubset()
+{
+}
+
+const std::string XdmfSubset::ItemTag = "Subset";
+
+shared_ptr<XdmfSubset>
+XdmfSubset::New(shared_ptr<XdmfArray> referenceArray,
+ std::vector<unsigned int> & start,
+ std::vector<unsigned int> & stride,
+ std::vector<unsigned int> & dimensions)
+{
+ shared_ptr<XdmfSubset> p(new XdmfSubset(referenceArray, start, stride, dimensions));
+ return p;
+}
+
+std::vector<unsigned int> XdmfSubset::getDimensions() const
+{
+ return mDimensions;
+}
+
+std::map<std::string, std::string>
+XdmfSubset::getItemProperties() const
+{
+ // Check to make sure the subset is valid
+ // before generating the properties.
+ if(!(mStart.size() == mStride.size() &&
+ mStride.size() == mDimensions.size())) {
+ XdmfError::message(XdmfError::FATAL,
+ "mStart, mStride, mDimensions must all be of equal "
+ "length in XdmfSubset getItemProperties");
+ }
+
+ if (mStart.size() < 1 ||
+ mStride.size() < 1 ||
+ mDimensions.size() < 1) {
+ XdmfError::message(XdmfError::WARNING,
+ "mStart, mStride, mDimensions must have at least "
+ "one value contained within");
+ }
+
+ std::map<std::string, std::string> subsetMap = XdmfArrayReference::getItemProperties();
+
+ std::stringstream vectorStream;
+
+ vectorStream << mStart[0];
+
+ for (unsigned int i = 1; i < mStart.size(); ++i) {
+ vectorStream << " " << mStart[i];
+ }
+
+ subsetMap["SubsetStarts"] = vectorStream.str();
+
+ vectorStream.str(std::string());
+
+ vectorStream << mStride[0];
+
+ for (unsigned int i = 1; i < mStride.size(); ++i) {
+ vectorStream << " " << mStride[i];
+ }
+
+ subsetMap["SubsetStrides"] = vectorStream.str();
+
+ vectorStream.str(std::string());
+
+ vectorStream << mDimensions[0];
+
+ for (unsigned int i = 1; i < mDimensions.size(); ++i) {
+ vectorStream << " " << mDimensions[i];
+ }
+
+ subsetMap["SubsetDimensions"] = vectorStream.str();
+
+ return subsetMap;
+}
+
+std::string
+XdmfSubset::getItemTag() const
+{
+ return ItemTag;
+}
+
+shared_ptr<XdmfArray>
+XdmfSubset::getReferenceArray()
+{
+ if (mParent) {
+ return mParent;
+ }
+ else {
+ return shared_ptr<XdmfArray>();
+ }
+}
+
+unsigned int
+XdmfSubset::getSize() const
+{
+ return std::accumulate(mDimensions.begin(),
+ mDimensions.end(),
+ 1,
+ std::multiplies<unsigned int>());
+}
+
+std::vector<unsigned int>
+XdmfSubset::getStart() const
+{
+ return mStart;
+}
+
+std::vector<unsigned int>
+XdmfSubset::getStride() const
+{
+ return mStride;
+}
+
+void
+XdmfSubset::populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader)
+{
+ std::map<std::string, std::string>::const_iterator starts =
+ itemProperties.find("SubsetStarts");
+
+ boost::tokenizer<> tokens(starts->second);
+ for(boost::tokenizer<>::const_iterator iter = tokens.begin();
+ iter != tokens.end();
+ ++iter) {
+ mStart.push_back(atoi((*iter).c_str()));
+ }
+
+ std::map<std::string, std::string>::const_iterator strides =
+ itemProperties.find("SubsetStrides");
+
+ boost::tokenizer<> stridetokens(strides->second);
+ for(boost::tokenizer<>::const_iterator iter = stridetokens.begin();
+ iter != stridetokens.end();
+ ++iter) {
+ mStride.push_back(atoi((*iter).c_str()));
+ }
+
+ std::map<std::string, std::string>::const_iterator dimensions =
+ itemProperties.find("SubsetDimensions");
+
+ boost::tokenizer<> dimtokens(dimensions->second);
+ for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
+ iter != dimtokens.end();
+ ++iter) {
+ mDimensions.push_back(atoi((*iter).c_str()));
+ }
+
+ mParent = shared_dynamic_cast<XdmfArray>(childItems[0]);
+}
+
+shared_ptr<XdmfArray>
+XdmfSubset::read() const
+{
+ if (mStart.size() < 1 ||
+ mStride.size() < 1 ||
+ mDimensions.size() < 1) {
+ XdmfError::message(XdmfError::WARNING,
+ "mStart, mStride, mDimensions must have at least "
+ "one value contained within");
+ }
+
+ if (!mParent->isInitialized()) {
+ mParent->read();
+ }
+
+ shared_ptr<XdmfArray> tempArray = XdmfArray::New();
+ tempArray->initialize(mParent->getArrayType());
+ tempArray->resize(this->getSize(), 0);
+ std::vector<unsigned int> writeStarts;
+ writeStarts.push_back(0);
+ std::vector<unsigned int> writeStrides;
+ writeStrides.push_back(1);
+ std::vector<unsigned int> writeDimensions;
+ writeDimensions.push_back(this->getSize());
+
+ tempArray->insert(writeStarts,
+ mParent,
+ mStart,
+ mDimensions,
+ writeDimensions,
+ writeStrides,
+ mStride);
+ return tempArray;
+}
+
+void
+XdmfSubset::setDimensions(std::vector<unsigned int> newDimensions)
+{
+ mDimensions = newDimensions;
+ // Give the user a warning so they know they might have messed something up.
+ // If they don't want the warning they can suppress it.
+ if(!(mStart.size() == mStride.size() &&
+ mStride.size() == mDimensions.size())) {
+ XdmfError::message(XdmfError::WARNING,
+ "mStart, mStride, mDimensions now have different sizes."
+ "The sizes should be equal before use.");
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfSubset::setReferenceArray(shared_ptr<XdmfArray> newReference)
+{
+ mParent = newReference;
+ this->setIsChanged(true);
+}
+
+void
+XdmfSubset::setStart(std::vector<unsigned int> newStarts)
+{
+ mStart = newStarts;
+ // Give the user a warning so they know they might have messed something up.
+ // If they don't want the warning they can suppress it.
+ if(!(mStart.size() == mStride.size() &&
+ mStride.size() == mDimensions.size())) {
+ XdmfError::message(XdmfError::WARNING,
+ "mStart, mStride, mDimensions now have different sizes."
+ "The sizes should be equal before use.");
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfSubset::setStride(std::vector<unsigned int> newStrides)
+{
+ mStride = newStrides;
+ // Give the user a warning so they know they might have messed something up.
+ // If they don't want the warning they can suppress it.
+ if(!(mStart.size() == mStride.size() &&
+ mStride.size() == mDimensions.size())) {
+ XdmfError::message(XdmfError::WARNING,
+ "mStart, mStride, mDimensions now have different sizes."
+ "The sizes should be equal before use.");
+ }
+ this->setIsChanged(true);
+}
+
+void
+XdmfSubset::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ XdmfItem::traverse(visitor);
+
+ bool originalXPath;
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ originalXPath = writer->getWriteXPaths();
+ writer->setWriteXPaths(false);
+ }
+
+ shared_ptr<XdmfArray> spacerarray = XdmfArray::New();
+ spacerarray->pushBack((int)0);
+ spacerarray->accept(visitor);
+
+ if (shared_ptr<XdmfWriter> writer =
+ shared_dynamic_cast<XdmfWriter>(visitor)) {
+ writer->setWriteXPaths(originalXPath);
+ }
+
+ mParent->accept(visitor);
+}
+
+// C Wrappers
+
+XDMFSUBSET * XdmfSubsetNew(void * referenceArray, unsigned int * start, unsigned int * stride, unsigned int * dimensions, unsigned int numDims, int passControl, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ shared_ptr<XdmfArray> referencePointer;
+ if (passControl) {
+ referencePointer = shared_ptr<XdmfArray>((XdmfArray *)referenceArray);
+ }
+ else {
+ referencePointer = shared_ptr<XdmfArray>((XdmfArray *)referenceArray, XdmfNullDeleter());
+ }
+ shared_ptr<XdmfSubset> generatedSubset = XdmfSubset::New(referencePointer, startVector, strideVector, dimVector);
+ return (XDMFSUBSET *)((void *)(new XdmfSubset(*generatedSubset.get())));
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ shared_ptr<XdmfArray> referencePointer;
+ if (passControl) {
+ referencePointer = shared_ptr<XdmfArray>((XdmfArray *)referenceArray);
+ }
+ else {
+ referencePointer = shared_ptr<XdmfArray>((XdmfArray *)referenceArray, XdmfNullDeleter());
+ }
+ shared_ptr<XdmfSubset> generatedSubset = XdmfSubset::New(referencePointer, startVector, strideVector, dimVector);
+ return (XDMFSUBSET *)((void *)(new XdmfSubset(*generatedSubset.get())));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+unsigned int * XdmfSubsetGetDimensions(XDMFSUBSET * subset)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfSubset *)(subset))->getDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfSubset *)(subset))->getDimensions();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+unsigned int XdmfSubsetGetNumberDimensions(XDMFSUBSET * subset)
+{
+ return ((XdmfSubset *)(subset))->getDimensions().size();
+}
+
+void * XdmfSubsetGetReferenceArray(XDMFSUBSET * subset)
+{
+ shared_ptr<XdmfArray> returnItem = ((XdmfSubset *)subset)->getReferenceArray();
+ return returnItem.get();
+}
+
+unsigned int XdmfSubsetGetSize(XDMFSUBSET * subset)
+{
+ return ((XdmfSubset *)(subset))->getSize();
+}
+
+unsigned int * XdmfSubsetGetStart(XDMFSUBSET * subset)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfSubset *)(subset))->getStart();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfSubset *)(subset))->getStart();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+unsigned int * XdmfSubsetGetStride(XDMFSUBSET * subset)
+{
+ try
+ {
+ std::vector<unsigned int> tempVector = ((XdmfSubset *)(subset))->getStride();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> tempVector = ((XdmfSubset *)(subset))->getStride();
+ unsigned int returnSize = tempVector.size();
+ unsigned int * returnArray = new unsigned int[returnSize]();
+ for (unsigned int i = 0; i < returnSize; ++i) {
+ returnArray[i] = tempVector[i];
+ }
+ return returnArray;
+ }
+}
+
+void XdmfSubsetSetDimensions(XDMFSUBSET * subset, unsigned int * newDimensions, unsigned int numDims, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<unsigned int> dimVector(newDimensions, newDimensions + numDims);
+ ((XdmfSubset *)(subset))->setDimensions(dimVector);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfSubsetSetReferenceArray(XDMFSUBSET * subset, XDMFARRAY * referenceArray, int passControl)
+{
+ shared_ptr<XdmfArray> referencePointer;
+ if (passControl) {
+ referencePointer = shared_ptr<XdmfArray>((XdmfArray *)referenceArray);
+ }
+ else {
+ referencePointer = shared_ptr<XdmfArray>((XdmfArray *)referenceArray, XdmfNullDeleter());
+ }
+ ((XdmfSubset *)subset)->setReferenceArray(referencePointer);
+}
+
+void XdmfSubsetSetStart(XDMFSUBSET * subset, unsigned int * newStarts, unsigned int numDims, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<unsigned int> startVector(newStarts, newStarts + numDims);
+ ((XdmfSubset *)(subset))->setStart(startVector);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfSubsetSetStride(XDMFSUBSET * subset, unsigned int * newStrides, unsigned int numDims, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ std::vector<unsigned int> strideVector(newStrides, newStrides + numDims);
+ ((XdmfSubset *)(subset))->setStride(strideVector);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_WRAPPER(XdmfSubset, XDMFSUBSET)
+XDMF_ARRAYREFERENCE_C_CHILD_WRAPPER(XdmfSubset, XDMFSUBSET)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSubset.hpp */
+/* */
+/* Author: */
+/* Andrew Burns */
+/* andrew.j.burns2@us.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2013 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFSUBSET_HPP_
+#define XDMFSUBSET_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfArrayReference.hpp"
+#include "XdmfItem.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+
+// Includes
+#include <vector>
+#include "XdmfSharedPtr.hpp"
+
+/**
+ * @brief Couples an XdmfArray with heavy data stored in another XdmfArray.
+ *
+ * This class serves to allow an array to retrieve data that is a subsection
+ * of an already existing array.
+ */
+class XDMFCORE_EXPORT XdmfSubset: public XdmfArrayReference {
+
+public:
+
+ /**
+ * Generates an XdmfSubset object based on the parameters provided
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param referenceArray The array that the subset is generated from.
+ * @param start A vector of the starting points for each
+ * dimension.
+ * @param stride A vector of the strides for each dimension.
+ * @param dimensions A vector of the amount of values read from each
+ * dimension.
+ * @return A constructed XdmfSubset
+ */
+ static shared_ptr<XdmfSubset>
+ New(shared_ptr<XdmfArray> referenceArray,
+ std::vector<unsigned int> & start,
+ std::vector<unsigned int> & stride,
+ std::vector<unsigned int> & dimensions);
+
+ virtual ~XdmfSubset();
+
+ LOKI_DEFINE_VISITABLE(XdmfSubset, XdmfItem)
+ static const std::string ItemTag;
+
+ /**
+ * Get the dimensions of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ *
+ * @return A vector containing the size in each dimension of the
+ * set referenced by this subset.
+ */
+ std::vector<unsigned int> getDimensions() const;
+
+ std::map<std::string, std::string> getItemProperties() const;
+
+ std::string getItemTag() const;
+
+ /**
+ * Gets the array that the subset pulls data from.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getReferenceArray
+ * @until //#getReferenceArray
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getReferenceArray
+ * @until #//getReferenceArray
+ *
+ * @return The array that the subset pulls data from
+ */
+ shared_ptr<XdmfArray> getReferenceArray();
+
+ /**
+ * Get the size of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getSize
+ * @until //#getSize
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getSize
+ * @until #//getSize
+ *
+ * @return An int containing the size of the subset.
+ */
+ unsigned int getSize() const;
+
+ /**
+ * Get the start index of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getStart
+ * @until //#getStart
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getStart
+ * @until #//getStart
+ *
+ * @return A vector containing the start index in each dimension of
+ * the set referenced by this subset.
+ */
+ std::vector<unsigned int> getStart() const;
+
+ /**
+ * Get the stride of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getStride
+ * @until //#getStride
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getStride
+ * @until #//getStride
+ *
+ * @return A vector containing the stride in each dimension of the
+ * heavy data set owned by this controller.
+ */
+ std::vector<unsigned int> getStride() const;
+
+ /**
+ * Read data reference by this subset and return as an XdmfArray.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#read
+ * @until //#read
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//read
+ * @until #//read
+ *
+ * @return An array filled with data based on the subset's parameters.
+ */
+ virtual shared_ptr<XdmfArray> read() const;
+
+ /**
+ * Set the dimensions of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getDimensions
+ * @until //#getDimensions
+ * @skipline //#setDimensions
+ * @until //#setDimensions
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getDimensions
+ * @until #//getDimensions
+ * @skipline #//setDimensions
+ * @until #//setDimensions
+ *
+ * @param newDimensions A vector containing the size in each dimension
+ * of the set to be referenced by this subset.
+ */
+ void setDimensions(std::vector<unsigned int> newDimensions);
+
+ /**
+ * Set the Array that the subset is generated from.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getReferenceArray
+ * @until //#getReferenceArray
+ * @skipline //#setReferenceArray
+ * @until //#setReferenceArray
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getReferenceArray
+ * @until #//getReferenceArray
+ * @skipline #//setReferenceArray
+ * @until #//setReferenceArray
+ *
+ * @param newReference A shared pointer to the array that the subset
+ * will be generated from
+ */
+ void setReferenceArray(shared_ptr<XdmfArray> newReference);
+
+ /**
+ * Set the start index of the set referenced by this subset.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getStart
+ * @until //#getStart
+ * @skipline //#setStart
+ * @until //#setStart
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getStart
+ * @until #//getStart
+ * @skipline #//setStart
+ * @until #//setStart
+ *
+ * @param newStarts A vector containing the start index in each
+ * dimension of the set to be referenced by this
+ * subset.
+ */
+ void setStart(std::vector<unsigned int> newStarts);
+
+ /**
+ * Set the stride of the heavy data set owned by this controller.
+ *
+ * Example of use:
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSubset.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ * @skipline //#getStride
+ * @until //#getStride
+ * @skipline //#setStride
+ * @until //#setStride
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSubset.py
+ * @skipline #//initialization
+ * @until #//initialization
+ * @skipline #//getStride
+ * @until #//getStride
+ * @skipline #//setStride
+ * @until #//setStride
+ *
+ * @param newStrides A vector containing the stride in each
+ * dimension of the set referenced by this subset.
+ */
+ void setStride(std::vector<unsigned int> newStrides);
+
+ void traverse(const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfSubset(XdmfSubset&);
+
+protected:
+
+ XdmfSubset(shared_ptr<XdmfArray> referenceArray,
+ std::vector<unsigned int> & start,
+ std::vector<unsigned int> & stride,
+ std::vector<unsigned int> & dimensions);
+
+ void
+ populateItem(const std::map<std::string, std::string> & itemProperties,
+ const std::vector<shared_ptr<XdmfItem> > & childItems,
+ const XdmfCoreReader * const reader);
+
+ shared_ptr<XdmfArray> mParent;
+ std::vector<unsigned int> mDimensions;
+ std::vector<unsigned int> mStart;
+ std::vector<unsigned int> mStride;
+
+private:
+
+ XdmfSubset(const XdmfSubset&); // Not implemented.
+ void operator=(const XdmfSubset &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFSUBSET; // Simply as a typedef to ensure correct typing
+typedef struct XDMFSUBSET XDMFSUBSET;
+
+XDMFCORE_EXPORT XDMFSUBSET * XdmfSubsetNew(void * referenceArray, unsigned int * start, unsigned int * stride, unsigned int * dimensions, unsigned int numDims, int passControl, int * status);
+
+XDMFCORE_EXPORT unsigned int * XdmfSubsetGetDimensions(XDMFSUBSET * subset);
+
+XDMFCORE_EXPORT unsigned int XdmfSubsetGetNumberDimensions(XDMFSUBSET * subset);
+
+XDMFCORE_EXPORT void * XdmfSubsetGetReferenceArray(XDMFSUBSET * subset);
+
+XDMFCORE_EXPORT unsigned int XdmfSubsetGetSize(XDMFSUBSET * subset);
+
+XDMFCORE_EXPORT unsigned int * XdmfSubsetGetStart(XDMFSUBSET * subset);
+
+XDMFCORE_EXPORT unsigned int * XdmfSubsetGetStride(XDMFSUBSET * subset);
+
+XDMFCORE_EXPORT void XdmfSubsetSetDimensions(XDMFSUBSET * subset, unsigned int * newDimensions, unsigned int numDims, int * status);
+
+XDMFCORE_EXPORT void XdmfSubsetSetReferenceArray(XDMFSUBSET * subset, XDMFARRAY * referenceArray, int passControl);
+
+XDMFCORE_EXPORT void XdmfSubsetSetStart(XDMFSUBSET * subset, unsigned int * newStarts, unsigned int numDims, int * status);
+
+XDMFCORE_EXPORT void XdmfSubsetSetStride(XDMFSUBSET * subset, unsigned int * newStrides, unsigned int numDims, int * status);
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_ITEM_C_CHILD_DECLARE(XdmfSubset, XDMFSUBSET, XDMFCORE)
+XDMF_ARRAYREFERENCE_C_CHILD_DECLARE(XdmfSubset, XDMFSUBSET, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFSUBSET_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSystemUtils.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "vtk_libxml2.h"
+#include VTKLIBXML2_HEADER(uri.h)
+#include <limits.h>
+#include <stdlib.h>
+#include "XdmfSystemUtils.hpp"
+#include "XdmfCoreConfig.hpp"
+#include <iostream>
+#include "string.h"
+
+XdmfSystemUtils::XdmfSystemUtils()
+{
+}
+
+XdmfSystemUtils::~XdmfSystemUtils()
+{
+}
+
+#ifdef XDMF_NO_REALPATH
+//allows symbolic links
+std::string
+XdmfSystemUtils::getRealPath(const std::string & path)
+{
+ return path;
+}
+#else
+std::string
+XdmfSystemUtils::getRealPath(const std::string & path)
+{
+ xmlURIPtr ref = NULL;
+ ref = xmlCreateURI();
+ xmlParseURIReference(ref, path.c_str());
+#ifdef WIN32
+ char realPath[_MAX_PATH];
+ _fullpath(realPath, path.c_str(), _MAX_PATH);
+ xmlFreeURI(ref);
+ return realPath;
+#else
+ char realPath[PATH_MAX];
+ char *rp = realpath(ref->path, realPath);
+ if (rp == 0)
+ {
+ //indicates a failure that we are silently ignoring
+ //TODO: realPath is now undefined but in practice
+ //ends up path.c_str()
+ rp = realPath;
+ }
+ xmlFreeURI(ref);
+ return std::string(rp);
+#endif
+}
+#endif
+
+char * XdmfSystemUtilsGetRealPath(char * path)
+{
+ std::string returnstring = XdmfSystemUtils::getRealPath(std::string(path));
+ char * returnPointer = strdup(returnstring.c_str());
+ return returnPointer;
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfSystemUtils.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFSYSTEMUTILS_HPP_
+#define XDMFSYSTEMUTILS_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+
+#ifdef __cplusplus
+
+// Includes
+#include <string>
+
+/**
+ * @brief System specific functions.
+ *
+ * Collects all system specific functions needed by Xdmf.
+ */
+class XDMFCORE_EXPORT XdmfSystemUtils {
+
+ public:
+
+ /**
+ * Converts a filesystem path to an absolute real path (absolute
+ * path with no symlinks)
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfSystemUtils.cpp
+ * @skipline //#getRealPath
+ * @until //#getRealPath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleSystemUtils.py
+ * @skipline #//getRealPath
+ * @until #//getRealPath
+ *
+ * @param path a string containing the path to convert.
+ *
+ * @return the equivalent real path.
+ */
+ static std::string getRealPath(const std::string & path);
+
+ protected:
+
+ XdmfSystemUtils();
+ ~XdmfSystemUtils();
+
+ private:
+
+ XdmfSystemUtils(const XdmfSystemUtils &); // Not implemented.
+ void operator=(const XdmfSystemUtils &); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+XDMFCORE_EXPORT char * XdmfSystemUtilsGetRealPath(char * path);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* XDMFSYSTEMUTILS_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* Xdmf */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTIFFController.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <fstream>
+#include <sstream>
+#include "XdmfArray.hpp"
+#include "XdmfArrayType.hpp"
+#include "XdmfTIFFController.hpp"
+#include "XdmfError.hpp"
+
+#include "tiff.h"
+#include "tiffio.h"
+
+shared_ptr<XdmfTIFFController>
+XdmfTIFFController::New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & dimensions)
+{
+ shared_ptr<XdmfTIFFController> p(new XdmfTIFFController(filePath,
+ type,
+ std::vector<unsigned int>(dimensions.size(), 0),
+ std::vector<unsigned int>(dimensions.size(), 1),
+ dimensions,
+ dimensions));
+ return p;
+}
+
+shared_ptr<XdmfTIFFController>
+XdmfTIFFController::New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces)
+{
+ shared_ptr<XdmfTIFFController> p(new XdmfTIFFController(filePath,
+ type,
+ starts,
+ strides,
+ dimensions,
+ dataspaces));
+ return p;
+}
+
+XdmfTIFFController::XdmfTIFFController(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces) :
+ XdmfHeavyDataController(filePath,
+ type,
+ starts,
+ strides,
+ dimensions,
+ dataspaces)
+{
+}
+
+XdmfTIFFController::XdmfTIFFController(const XdmfTIFFController& refController):
+ XdmfHeavyDataController(refController)
+{
+}
+
+XdmfTIFFController::~XdmfTIFFController()
+{
+}
+
+shared_ptr<XdmfHeavyDataController>
+XdmfTIFFController::createSubController(const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions)
+{
+ return XdmfTIFFController::New(mFilePath,
+ mType,
+ starts,
+ strides,
+ dimensions,
+ mDataspaceDimensions);
+}
+
+void
+XdmfTIFFController::readToArray(XdmfArray * const array,
+ void * pointer,
+ unsigned int offset,
+ unsigned int start,
+ unsigned int stride,
+ unsigned int amount,
+ shared_ptr<const XdmfArrayType> type)
+{
+ if (type == XdmfArrayType::UInt64())
+ {
+ uint64_t * offsetpointer = &(((uint64_t *)pointer)[start]);
+ array->insert(offset,
+ offsetpointer,
+ amount,
+ 1,
+ stride);
+ }
+ else if (type == XdmfArrayType::UInt32())
+ {
+ unsigned int * offsetpointer = &(((unsigned int *)pointer)[start]);
+ array->insert(offset,
+ offsetpointer,
+ amount,
+ 1,
+ stride);
+ }
+ else if (type == XdmfArrayType::UInt16())
+ {
+ unsigned short * offsetpointer = &(((unsigned short *)pointer)[start]);
+ array->insert(offset,
+ offsetpointer,
+ amount,
+ 1,
+ stride);
+ }
+ else if (type == XdmfArrayType::UInt8())
+ {
+ unsigned char * offsetpointer = &(((unsigned char *)pointer)[start]);
+ array->insert(offset,
+ offsetpointer,
+ amount,
+ 1,
+ stride);
+ }
+}
+
+std::string
+XdmfTIFFController::getName() const
+{
+ return "TIFF";
+}
+
+unsigned int
+XdmfTIFFController::getNumberDirectories() const
+{
+ TIFF* tif = TIFFOpen(mFilePath.c_str(), "r");
+ unsigned int count = 0;
+ if (tif) {
+ do {
+ count++;
+ } while (TIFFReadDirectory(tif));
+ TIFFClose(tif);
+ }
+ return count;
+}
+
+void
+XdmfTIFFController::getProperties(std::map<std::string, std::string> & collectedProperties) const
+{
+ collectedProperties["Format"] = this->getName();
+ std::stringstream seekStream;
+}
+
+void
+XdmfTIFFController::read(XdmfArray * const array)
+{
+ TIFF* tif = TIFFOpen(mFilePath.c_str(), "r");
+
+ unsigned int compression = 0;
+
+ TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression);
+
+ unsigned int currentDirectory = 0;
+
+ if (tif && mStart.size() >= 3) {
+ // setting the start for the first directory
+ TIFFSetDirectory(tif, mStart[2]);
+ currentDirectory = mStart[2];
+ }
+
+ unsigned int amountWritten = 0;
+ // Only used for 1d controllers
+ unsigned int sizeLeft = this->getSize();
+ if (!array->isInitialized()) {
+ array->initialize(this->getType());
+ }
+ if (array->getSize() != this->getSize()) {
+ array->resize(mDimensions, 0);
+ }
+
+ // For single dimension version only
+ unsigned int currentRowStart = mStart[0];
+ unsigned int scanlineIndex = 0;
+
+ if (mDimensions.size() > 1)
+ {
+ scanlineIndex = mStart[1];
+ }
+
+ if (tif) {
+ bool validDir = true;
+ while (validDir) {
+ // Directories are handled by the third dimension
+ // If no directories are specified, progress as far
+ // as needed to fill the dimensions provided.
+ unsigned int imagelength, bitsPerSample;
+ tdata_t buf;
+ unsigned int row;
+ unsigned int scanlinesize = TIFFScanlineSize(tif);
+
+ shared_ptr<const XdmfArrayType> tiffDataType = array->getArrayType();
+
+ TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitsPerSample);
+
+ TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
+
+ if (compression == 1) {
+ // Specific to non-compressed read
+
+ if (bitsPerSample / 8 == 1) {
+ tiffDataType = XdmfArrayType::UInt8();
+ }
+ else if (bitsPerSample / 8 == 2) {
+ tiffDataType = XdmfArrayType::UInt16();
+ }
+ else if (bitsPerSample / 8 == 4) {
+ tiffDataType = XdmfArrayType::UInt32();
+ }
+ else if (bitsPerSample / 8 == 8) {
+ tiffDataType = XdmfArrayType::UInt64();
+ }
+
+ // the buffer is a number of bytes equal to the scan line size
+ buf = _TIFFmalloc(scanlinesize );
+
+ scanlinesize /= array->getArrayType()->getElementSize();
+
+ if (mDimensions.size() == 1)
+ {
+ if (sizeLeft == 0) {
+ break;
+ }
+ // If there is one dimensions then we treat the entire entry as a single dataset.
+ // We need to adjust the starting point accordingly.
+ for (row = 0; row < imagelength; ++row)
+ {
+ TIFFReadScanline(tif, buf, row);
+ unsigned int amountRead = sizeLeft;
+ if ((scanlinesize - currentRowStart) / mStride[0] <= sizeLeft) {
+ amountRead = (scanlinesize - currentRowStart) / mStride[0];
+ if (scanlinesize % mStride[0] != 0 &&
+ currentRowStart % mStride[0] <= scanlinesize - (amountRead * mStride[0] + currentRowStart))
+ {
+ amountRead++;
+ }
+ }
+ readToArray(array,
+ buf,
+ amountWritten,
+ currentRowStart,
+ mStride[0],
+ amountRead,
+ tiffDataType);
+ // check to see how the start matches up with the scanline size
+ amountWritten += amountRead;
+ if (sizeLeft == 0) {
+ break;
+ }
+
+ if (amountRead < sizeLeft) {
+ sizeLeft = sizeLeft - amountRead;
+ }
+ else {
+ sizeLeft = 0;
+ }
+ if (((int)((amountRead * mStride[0]) + currentRowStart)) - scanlinesize >= 0)
+ {
+ currentRowStart = ((amountRead * mStride[0]) + currentRowStart) - scanlinesize;
+ }
+ else
+ {
+ currentRowStart = ((amountRead * (mStride[0] + 1)) + currentRowStart) - scanlinesize;
+ }
+ }
+ }
+ else {
+ // Dimensions correspond to scanline size and number of scanlines
+ unsigned int rowstride = mStride[1];
+ unsigned int currentRowStart = mStart[0];
+ for (row = mStart[1]; row < imagelength && row < mDataspaceDimensions[1]; row+=rowstride)
+ {
+ TIFFReadScanline(tif, buf, row);
+ readToArray(array,
+ buf,
+ amountWritten,
+ currentRowStart,
+ mStride[0],
+ mDimensions[0],
+ tiffDataType);
+ amountWritten += mDimensions[0];
+ }
+ }
+ _TIFFfree(buf);
+
+ }
+ else if (compression == 5)
+ {
+ // In this case we need to use strips instead of scanlines
+ // scanline size is in bytes when dealing with compression
+ if (bitsPerSample == 1) {
+ tiffDataType = XdmfArrayType::UInt8();
+ }
+ else if (bitsPerSample == 2) {
+ tiffDataType = XdmfArrayType::UInt16();
+ }
+ else if (bitsPerSample == 4) {
+ tiffDataType = XdmfArrayType::UInt32();
+ }
+ else if (bitsPerSample == 8) {
+ tiffDataType = XdmfArrayType::UInt64();
+ }
+
+ // the buffer is a number of bytes equal to the scan line size
+ buf = _TIFFmalloc(TIFFStripSize(tif));
+
+ scanlinesize /= array->getArrayType()->getElementSize();
+
+ // For each strip in the directory
+ for (unsigned int strip = 0; strip < TIFFNumberOfStrips(tif); strip++)
+ {
+ if (sizeLeft == 0) {
+ break;
+ }
+
+ unsigned int currentStripSize = TIFFReadEncodedStrip(tif, strip, buf, -1);
+ currentStripSize = currentStripSize / array->getArrayType()->getElementSize();
+ // Size is in bits, and is not necessarily the same per strip
+ unsigned int numberScanlines = currentStripSize / scanlinesize;
+ // For the case of a partial scanline
+ if (currentStripSize % scanlinesize != 0) {
+ ++numberScanlines;
+ }
+ // If singledimensional
+ // then write out the strip as if it was a scanline
+
+ if (mDimensions.size() == 1)
+ {
+ unsigned int amountRead = sizeLeft;
+ if ((currentStripSize - currentRowStart) / mStride[0] <= sizeLeft) {
+ amountRead = (currentStripSize - currentRowStart) / mStride[0];
+ if (currentStripSize % mStride[0] != 0 &&
+ currentRowStart % mStride[0] <= currentStripSize - (amountRead * mStride[0] + currentRowStart))
+ {
+ amountRead++;
+ }
+ }
+ readToArray(array,
+ buf,
+ amountWritten,
+ currentRowStart,
+ mStride[0],
+ amountRead,
+ tiffDataType);
+ amountWritten += amountRead;
+ if (sizeLeft == 0) {
+ break;
+ }
+
+ if (amountRead < sizeLeft) {
+ sizeLeft = sizeLeft - amountRead;
+ }
+ else {
+ sizeLeft = 0;
+ }
+ if (((int)((amountRead * mStride[0]) + currentRowStart)) - currentStripSize >= 0)
+ {
+ currentRowStart = ((amountRead * mStride[0]) + currentRowStart) - currentStripSize;
+ }
+ else
+ {
+ currentRowStart = ((amountRead * (mStride[0] + 1)) + currentRowStart) - currentStripSize;
+ }
+ }
+ else
+ {
+ currentRowStart = scanlineIndex;
+ // If multidimensional
+ // Loop through the scanlines in the strip
+ for (; scanlineIndex < numberScanlines; scanlineIndex += mStride[1])
+ {
+ readToArray(array,
+ buf,
+ amountWritten,
+ currentRowStart,
+ mStride[0],
+ mDimensions[0],
+ tiffDataType);
+ amountWritten += mDimensions[0];
+ currentRowStart = currentRowStart + scanlinesize * mStride[1];
+ }
+ scanlineIndex = scanlineIndex % mStride[1];
+ }
+ }
+ }
+
+ if (mStride.size() >= 3)
+ {
+ currentDirectory += mStride[2];
+ }
+ else
+ {
+ ++currentDirectory;
+ }
+
+ validDir = TIFFSetDirectory(tif, currentDirectory);
+ }
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL, "Error: Invalid TIFF file");
+ }
+
+ TIFFClose(tif);
+}
+
+// C Wrappers
+
+XDMFTIFFCONTROLLER * XdmfTIFFControllerNew(char * filePath,
+ int type,
+ unsigned int * dimensions,
+ unsigned int numDims,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfTIFFController> generatedController = XdmfTIFFController::New(std::string(filePath), buildType, dimVector);
+ return (XDMFTIFFCONTROLLER *)((void *)(new XdmfTIFFController(*generatedController.get())));
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfTIFFController> generatedController = XdmfTIFFController::New(std::string(filePath), buildType, dimVector);
+ return (XDMFTIFFCONTROLLER *)((void *)(new XdmfTIFFController(*generatedController.get())));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFTIFFCONTROLLER * XdmfTIFFControllerNewHyperslab(char * filePath,
+ int type,
+ unsigned int * start,
+ unsigned int * stride,
+ unsigned int * dimensions,
+ unsigned int * dataspaceDimensions,
+ unsigned int numDims,
+ int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ try
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfTIFFController> generatedController = XdmfTIFFController::New(std::string(filePath), buildType, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFTIFFCONTROLLER *)((void *)(new XdmfTIFFController(*generatedController.get())));
+ }
+ catch (...)
+ {
+ std::vector<unsigned int> startVector(start, start + numDims);
+ std::vector<unsigned int> strideVector(stride, stride + numDims);
+ std::vector<unsigned int> dimVector(dimensions, dimensions + numDims);
+ std::vector<unsigned int> dataspaceVector(dataspaceDimensions, dataspaceDimensions + numDims);
+ shared_ptr<const XdmfArrayType> buildType = shared_ptr<XdmfArrayType>();
+ switch (type) {
+ case XDMF_ARRAY_TYPE_UINT8:
+ buildType = XdmfArrayType::UInt8();
+ break;
+ case XDMF_ARRAY_TYPE_UINT16:
+ buildType = XdmfArrayType::UInt16();
+ break;
+ case XDMF_ARRAY_TYPE_UINT32:
+ buildType = XdmfArrayType::UInt32();
+ break;
+ case XDMF_ARRAY_TYPE_UINT64:
+ buildType = XdmfArrayType::UInt64();
+ break;
+ case XDMF_ARRAY_TYPE_INT8:
+ buildType = XdmfArrayType::Int8();
+ break;
+ case XDMF_ARRAY_TYPE_INT16:
+ buildType = XdmfArrayType::Int16();
+ break;
+ case XDMF_ARRAY_TYPE_INT32:
+ buildType = XdmfArrayType::Int32();
+ break;
+ case XDMF_ARRAY_TYPE_INT64:
+ buildType = XdmfArrayType::Int64();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT32:
+ buildType = XdmfArrayType::Float32();
+ break;
+ case XDMF_ARRAY_TYPE_FLOAT64:
+ buildType = XdmfArrayType::Float64();
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid ArrayType.");
+ break;
+ }
+ shared_ptr<XdmfTIFFController> generatedController = XdmfTIFFController::New(std::string(filePath), buildType, startVector, strideVector, dimVector, dataspaceVector);
+ return (XDMFTIFFCONTROLLER *)((void *)(new XdmfTIFFController(*generatedController.get())));
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+// C Wrappers for parent classes are generated by macros
+
+XDMF_HEAVYCONTROLLER_C_CHILD_WRAPPER(XdmfTIFFController, XDMFTIFFCONTROLLER)
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfTIFFController.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFTIFFCONTROLLER_HPP_
+#define XDMFTIFFCONTROLLER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataController.hpp"
+
+#ifdef __cplusplus
+
+/**
+ * @brief Couples an XdmfArray with TIFF data stored on disk.
+ *
+ * Serves as an interface between data stored in XdmfArrays and data
+ * stored in tiff files on disk. When an Xdmf file is read from or
+ * written to disk an XdmfTIFFController is attached to
+ * XdmfArrays. This allows data to be released from memory but still
+ * be accessible or have its location written to light data.
+ */
+class XDMFCORE_EXPORT XdmfTIFFController : public XdmfHeavyDataController {
+
+public:
+
+ virtual ~XdmfTIFFController();
+
+ /**
+ * Create a new controller for an TIFF file on disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTIFFController.cpp
+ * @skipline //#initializationsimplified
+ * @until //#initializationsimplified
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTIFFController.py
+ * @skipline #//initializationsimplified
+ * @until #//initializationsimplified
+ *
+ * @param filePath The location of the tiff file the data
+ * set resides in.
+ * @param type The data type of the dataset to read.
+ * @param dimensions The number of elements to select in each
+ * dimension from the data set.
+ * (size in each dimension)
+ *
+ * @return New TIFF Controller.
+ */
+ static shared_ptr<XdmfTIFFController>
+ New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & dimensions);
+
+ /**
+ * Create a new controller for an TIFF file on disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfTIFFController.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleTIFFController.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param filePath The location of the tiff file the data set resides in.
+ * @param type The data type of the dataset to read.
+ * @param starts The offset of the starting element in each
+ * dimension in the data set.
+ * @param strides The number of elements to move in each
+ * dimension from the data set.
+ * @param dimensions The number of elements to select in each
+ * dimension from the data set.
+ * (size in each dimension)
+ * @param dataspaces The number of elements in the entire
+ * data set (may be larger than
+ * dimensions if using hyperslabs).
+ *
+ * @return New TIFF Controller.
+ */
+ static shared_ptr<XdmfTIFFController>
+ New(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces);
+
+ virtual std::string getName() const;
+
+ virtual void
+ getProperties(std::map<std::string, std::string> & collectedProperties) const;
+
+ virtual void read(XdmfArray * const array);
+
+ XdmfTIFFController(const XdmfTIFFController &);
+
+protected:
+
+ XdmfTIFFController(const std::string & filePath,
+ const shared_ptr<const XdmfArrayType> & type,
+ const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions,
+ const std::vector<unsigned int> & dataspaces);
+
+ virtual shared_ptr<XdmfHeavyDataController>
+ createSubController(const std::vector<unsigned int> & starts,
+ const std::vector<unsigned int> & strides,
+ const std::vector<unsigned int> & dimensions);
+
+ unsigned int getNumberDirectories() const;
+
+ void readToArray(XdmfArray * const array,
+ void * pointer,
+ unsigned int offset,
+ unsigned int start,
+ unsigned int stride,
+ unsigned int amount,
+ shared_ptr<const XdmfArrayType> type);
+
+private:
+
+ void operator=(const XdmfTIFFController &); // Not implemented.
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct XDMFTIFFCONTROLLER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFTIFFCONTROLLER XDMFTIFFCONTROLLER;
+
+XDMFCORE_EXPORT XDMFTIFFCONTROLLER * XdmfTIFFControllerNew(char * filePath,
+ int type,
+ unsigned int * dimensions,
+ unsigned int numDims,
+ int * status);
+
+XDMFCORE_EXPORT XDMFTIFFCONTROLLER * XdmfTIFFControllerNewHyperslab(char * filePath,
+ int type,
+ unsigned int * starts,
+ unsigned int * strides,
+ unsigned int * dimensions,
+ unsigned int * dataspaces,
+ unsigned int numDims,
+ int * status);
+
+XDMF_HEAVYCONTROLLER_C_CHILD_DECLARE(XdmfTIFFController, XDMFTIFFCONTROLLER, XDMFCORE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFTIFFCONTROLLER_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* Xdmf */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfVisitor.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include "XdmfItem.hpp"
+#include "XdmfVisitor.hpp"
+
+XdmfVisitor::XdmfVisitor()
+{
+}
+
+XdmfVisitor::~XdmfVisitor()
+{
+}
+
+void
+XdmfVisitor::visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ item.traverse(visitor);
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfVisitor.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFVISITOR_HPP_
+#define XDMFVISITOR_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfItem;
+
+// Includes
+#include <loki/Visitor.h>
+
+/**
+ * @brief Perform an operation on an Xdmf tree structure.
+ *
+ * XdmfVisitor is an abstract base class for any operation that
+ * operates on an Xdmf tree structure. These operations could involve
+ * writing to disk or modifying the structure in some way.
+ */
+class XDMFCORE_EXPORT XdmfVisitor : public XdmfBaseVisitor,
+ public Loki::Visitor<XdmfItem> {
+
+public:
+
+ virtual ~XdmfVisitor() = 0;
+
+ virtual void visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor);
+
+protected:
+
+ XdmfVisitor();
+
+private:
+
+ XdmfVisitor(const XdmfVisitor & visitor); // Not implemented.
+ void operator=(const XdmfVisitor & visitor); // Not implemented.
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// C wrappers go here
+
+struct XDMFVISITOR; // Simply as a typedef to ensure correct typing
+typedef struct XDMFVISITOR XDMFVISITOR;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFVISITOR_HPP_ */
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfWriter.cpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#include <fstream>
+#include <sstream>
+#include <utility>
+#include "XdmfArray.hpp"
+#include "XdmfInformation.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+#include "XdmfHDF5Controller.hpp"
+#include "XdmfHDF5Writer.hpp"
+#include "XdmfItem.hpp"
+#include "XdmfSystemUtils.hpp"
+#include "XdmfWriter.hpp"
+#include "XdmfVersion.hpp"
+#include "XdmfError.hpp"
+#include "string.h"
+
+/**
+ * PIMPL
+ */
+class XdmfWriter::XdmfWriterImpl {
+
+public:
+
+ XdmfWriterImpl(const std::string & xmlFilePath,
+ const shared_ptr<XdmfHeavyDataWriter> heavyDataWriter,
+ std::ostream * stream) :
+ mDepth(0),
+ mDocumentTitle("Xdmf"),
+ mHeavyDataWriter(heavyDataWriter),
+ mHeavyWriterIsOpen(false),
+ mLastXPathed(false),
+ mLightDataLimit(100),
+ mMode(Default),
+ mStream(stream),
+ mWriteXPaths(true),
+ mXPathParse(true),
+ mXMLCurrentNode(NULL),
+ mXMLDocument(NULL),
+ mXMLFilePath(XdmfSystemUtils::getRealPath(xmlFilePath)),
+ mXPathCount(0),
+ mXPathString(""),
+ mVersionString(XdmfVersion.getShort())
+ {
+ };
+
+ ~XdmfWriterImpl()
+ {
+ };
+
+ void
+ closeFile()
+ {
+ mXPath.clear();
+ mXPathCount = 0;
+
+ // This section writes to file
+ std::ofstream fileStream;
+ if(!mStream) {
+ fileStream.open(mXMLFilePath.c_str());
+ mStream = &fileStream;
+ }
+
+ xmlBufferPtr buffer = xmlBufferCreate();
+ xmlOutputBuffer * outputBuffer = xmlOutputBufferCreateBuffer(buffer,
+ NULL);
+ xmlSaveFormatFileTo(outputBuffer,
+ mXMLDocument,
+ "utf-8",
+ 1);
+ *mStream << buffer->content;
+ xmlBufferFree(buffer);
+
+ if(fileStream.is_open()) {
+ fileStream.close();
+ mStream = NULL;
+ }
+
+// xmlFreeDoc(mXMLDocument);
+ xmlCleanupParser();
+
+ if(mHeavyDataWriter->getMode() == XdmfHeavyDataWriter::Default) {
+ if (mHeavyWriterIsOpen) {
+ mHeavyDataWriter->closeFile();
+ }
+ }
+ };
+
+ void
+ openFile()
+ {
+ mXMLDocument = xmlNewDoc((xmlChar*)"1.0");
+ mXMLCurrentNode = xmlNewNode(NULL, (xmlChar*)mDocumentTitle.c_str());
+ xmlNewProp(mXMLCurrentNode,
+ (xmlChar*)"xmlns:xi",
+ (xmlChar*)"http://www.w3.org/2001/XInclude");
+ xmlNewProp(mXMLCurrentNode,
+ (xmlChar*)"Version",
+ (xmlChar*)mVersionString.c_str());
+ xmlDocSetRootElement(mXMLDocument, mXMLCurrentNode);
+ if(mHeavyDataWriter->getMode() == XdmfHeavyDataWriter::Default) {
+ mHeavyDataWriter->openFile();
+ }
+ }
+
+ int mDepth;
+ std::string mDocumentTitle;
+ shared_ptr<XdmfHeavyDataWriter> mHeavyDataWriter;
+ bool mHeavyWriterIsOpen;
+ bool mLastXPathed;
+ unsigned int mLightDataLimit;
+ Mode mMode;
+ std::ostream * mStream;
+ bool mWriteXPaths;
+ bool mXPathParse;
+ xmlNodePtr mXMLCurrentNode;
+ xmlDocPtr mXMLDocument;
+ std::string mXMLFilePath;
+ std::map<const XdmfItem * const, std::string> mXPath;
+ unsigned int mXPathCount;
+ std::string mXPathString;
+ std::string mVersionString;
+
+};
+
+shared_ptr<XdmfWriter>
+XdmfWriter::New(const std::string & xmlFilePath)
+{
+ std::stringstream heavyFileName;
+ size_t extension = xmlFilePath.rfind(".");
+ if(extension != std::string::npos) {
+ heavyFileName << xmlFilePath.substr(0, extension) << ".h5";
+ }
+ else {
+ heavyFileName << xmlFilePath << ".h5";
+ }
+ shared_ptr<XdmfHDF5Writer> hdf5Writer =
+ XdmfHDF5Writer::New(heavyFileName.str());
+ shared_ptr<XdmfWriter> p(new XdmfWriter(xmlFilePath, hdf5Writer));
+ return p;
+}
+
+shared_ptr<XdmfWriter>
+XdmfWriter::New(const std::string & xmlFilePath,
+ const shared_ptr<XdmfHeavyDataWriter> heavyDataWriter)
+{
+ shared_ptr<XdmfWriter> p(new XdmfWriter(xmlFilePath,
+ heavyDataWriter));
+ return p;
+}
+
+shared_ptr<XdmfWriter>
+XdmfWriter::New(std::ostream & stream,
+ const shared_ptr<XdmfHeavyDataWriter> heavyDataWriter)
+{
+ shared_ptr<XdmfWriter> p(new XdmfWriter("",
+ heavyDataWriter,
+ &stream));
+ return p;
+}
+
+XdmfWriter::XdmfWriter(const std::string & xmlFilePath,
+ shared_ptr<XdmfHeavyDataWriter> heavyDataWriter,
+ std::ostream * stream) :
+ mRebuildAlreadyVisited(true),
+ mImpl(new XdmfWriterImpl(xmlFilePath,
+ heavyDataWriter,
+ stream))
+{
+}
+
+XdmfWriter::XdmfWriter(const XdmfWriter & writerRef) :
+ mRebuildAlreadyVisited(writerRef.mRebuildAlreadyVisited)
+{
+ char * transferPath = strdup(writerRef.getFilePath().c_str());
+ char * heavyTransferPath = strdup(writerRef.getHeavyDataWriter()->getFilePath().c_str());
+ mImpl = new XdmfWriterImpl(transferPath, XdmfHDF5Writer::New(heavyTransferPath), NULL);
+}
+
+XdmfWriter::~XdmfWriter()
+{
+ mXMLArchive.clear();
+ xmlFreeDoc(mImpl->mXMLDocument);
+ delete mImpl;
+}
+
+shared_ptr<XdmfHeavyDataWriter>
+XdmfWriter::getHeavyDataWriter()
+{
+ return boost::const_pointer_cast<XdmfHeavyDataWriter>
+ (static_cast<const XdmfWriter &>(*this).getHeavyDataWriter());
+}
+
+shared_ptr<const XdmfHeavyDataWriter>
+XdmfWriter::getHeavyDataWriter() const
+{
+ return mImpl->mHeavyDataWriter;
+}
+
+std::string
+XdmfWriter::getFilePath() const
+{
+ return mImpl->mXMLFilePath;
+}
+
+unsigned int
+XdmfWriter::getLightDataLimit() const
+{
+ return mImpl->mLightDataLimit;
+}
+
+XdmfWriter::Mode
+XdmfWriter::getMode() const
+{
+ return mImpl->mMode;
+}
+
+bool
+XdmfWriter::getRebuildXML()
+{
+ return mRebuildAlreadyVisited;
+}
+
+xmlNodePtr
+XdmfWriter::getXMLNode(XdmfItem * item, xmlDocPtr parentDoc, xmlNodePtr parentNode)
+{
+ std::map<XdmfItem *, xmlNodePtr>::iterator node =
+ mXMLArchive.find(item);
+ if (node != mXMLArchive.end())
+ {
+ xmlAddChild(parentNode, mXMLArchive[item]);
+ return mXMLArchive[item];
+ }
+ else
+ {
+ return xmlNewNode(NULL, (xmlChar*)"NULL");
+ }
+}
+
+bool
+XdmfWriter::getHasXMLArchive(XdmfItem * item)
+{
+ std::map<XdmfItem *, xmlNodePtr>::iterator node =
+ mXMLArchive.find(item);
+ if (node != mXMLArchive.end())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool
+XdmfWriter::getWriteXPaths() const
+{
+ return mImpl->mWriteXPaths;
+}
+
+bool
+XdmfWriter::getXPathParse() const
+{
+ return mImpl->mXPathParse;
+}
+
+void
+XdmfWriter::setDocumentTitle(std::string title)
+{
+ mImpl->mDocumentTitle = title;
+}
+
+void
+XdmfWriter::setHeavyDataWriter(shared_ptr<XdmfHeavyDataWriter> heavyDataWriter)
+{
+ mImpl->mHeavyDataWriter = heavyDataWriter;
+}
+
+void
+XdmfWriter::setLightDataLimit(const unsigned int numValues)
+{
+ mImpl->mLightDataLimit = numValues;
+}
+
+void
+XdmfWriter::setMode(const Mode mode)
+{
+ mImpl->mMode = mode;
+}
+
+void
+XdmfWriter::setRebuildXML(bool newStatus)
+{
+ mRebuildAlreadyVisited = newStatus;
+}
+
+void
+XdmfWriter::setVersionString(std::string version)
+{
+ mImpl->mVersionString = version;
+}
+
+void
+XdmfWriter::setXMLNode(XdmfItem * item, xmlNodePtr & newNode)
+{
+ mXMLArchive[item] = xmlCopyNode(newNode, 1);
+}
+
+void
+XdmfWriter::setWriteXPaths(const bool writeXPaths)
+{
+ mImpl->mWriteXPaths = writeXPaths;
+}
+
+void
+XdmfWriter::setXPathParse(const bool xPathParse)
+{
+ mImpl->mXPathParse = xPathParse;
+}
+
+void
+XdmfWriter::visit(XdmfArray & array,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ if (mImpl->mDepth == 0) {
+ mImpl->openFile();
+ }
+ mImpl->mDepth++;
+
+ // Pull the Function and Subset accociated with the array
+ shared_ptr<XdmfArrayReference> internalReference = array.getReference();
+
+ // If in the correct read mode process the function or subset
+ // if it exists
+ if (internalReference && array.getReadMode() == XdmfArray::Reference) {
+ // Pass information about the array to the function
+ // so it can properly recreate it when read
+ internalReference->setConstructedType(array.getItemTag());
+ internalReference->setConstructedProperties(array.getItemProperties());
+ internalReference->accept(visitor);
+ // This does not write the data contained within the array to file
+ // The data is regenerated upon read
+ }
+ else if (array.getReadMode() == XdmfArray::Controller) {
+ // Controller mode is the default mode
+ const bool isSubclassed =
+ array.getItemTag().compare(XdmfArray::ItemTag) != 0;
+
+ if(isSubclassed) {
+ this->visit(dynamic_cast<XdmfItem &>(array), visitor);
+ }
+
+ if(array.getSize() > 0 && !(mImpl->mLastXPathed && isSubclassed)) {
+ std::vector<std::string> xmlTextValues;
+
+ // Take care of writing to single heavy data file (Default behavior)
+ if(!array.isInitialized() && array.getHeavyDataController(0) &&
+ mImpl->mMode == Default) {
+ if (array.getHeavyDataController(0)->getFilePath().compare(mImpl->mHeavyDataWriter->getFilePath()) != 0)
+ {
+ array.read();
+ }
+ }
+
+ if(array.getHeavyDataController(0) ||
+ array.getSize() > mImpl->mLightDataLimit) {
+ // Write values to heavy data
+
+ // This takes about half the time needed
+ if ((!mImpl->mHeavyWriterIsOpen) &&
+ mImpl->mHeavyDataWriter->getMode() == XdmfHeavyDataWriter::Default) {
+ mImpl->mHeavyDataWriter->openFile();
+ mImpl->mHeavyWriterIsOpen = true;
+ }
+ mImpl->mHeavyDataWriter->visit(array, mImpl->mHeavyDataWriter);
+
+ std::stringstream valuesStream;
+ for(unsigned int i = 0; i < array.getNumberHeavyDataControllers(); ++i) {
+
+ std::string heavyDataPath =
+ array.getHeavyDataController(i)->getFilePath();
+ size_t index = heavyDataPath.find_last_of("/\\");
+ if(index != std::string::npos) {
+ // If path is not a folder
+ // put the directory path into this variable
+ const std::string heavyDataDir = heavyDataPath.substr(0, index + 1);
+ // If the directory is in the XML File Path
+ if(mImpl->mXMLFilePath.find(heavyDataDir) == 0) {
+ heavyDataPath =
+ heavyDataPath.substr(heavyDataDir.size(),
+ heavyDataPath.size() - heavyDataDir.size());
+ // Pull the file off of the end and place it in the DataPath
+ }
+ // Otherwise the full path is required
+ }
+ // Clear the stream
+ valuesStream.str(std::string());
+ valuesStream << heavyDataPath << array.getHeavyDataController(i)->getDescriptor();
+ if (array.getNumberHeavyDataControllers() > 1 ||
+ (array.getHeavyDataController(i)->getSize() !=
+ array.getHeavyDataController(i)->getDataspaceSize())) {
+ valuesStream << "|" << array.getHeavyDataController(i)->getDataspaceDescription();
+ if (i + 1 < array.getNumberHeavyDataControllers()) {
+ valuesStream << "|";
+ }
+ }
+ xmlTextValues.push_back(valuesStream.str());
+ }
+ }
+ else {
+ // Write values to XML
+ xmlTextValues.push_back(array.getValuesString());
+ }
+
+ bool oldWriteXPaths = mImpl->mWriteXPaths;
+
+ // Write XML (metadata) description
+ if(isSubclassed) {
+ // We don't want temporary items to be on the XPath List
+ // This is a one-of anyway, so it shouldn't be equivalent
+ // to anything written before now or after.
+ mImpl->mWriteXPaths = false;
+ const unsigned int parentCount = mImpl->mXPathCount;
+ mImpl->mXPathCount = 0;
+ shared_ptr<XdmfArray> arrayToWrite = XdmfArray::New();
+ array.swap(arrayToWrite);
+ mImpl->mXMLCurrentNode = mImpl->mXMLCurrentNode->last;
+ this->visit(dynamic_cast<XdmfItem &>(*arrayToWrite.get()), visitor);
+ for(unsigned int i = 0; i<xmlTextValues.size(); ++i) {
+ xmlAddChild(mImpl->mXMLCurrentNode->last,
+ xmlNewText((xmlChar*)xmlTextValues[i].c_str()));
+ }
+ mImpl->mXMLCurrentNode = mImpl->mXMLCurrentNode->parent;
+ array.swap(arrayToWrite);
+ mImpl->mXPathCount = parentCount;
+ mImpl->mLastXPathed = false;
+ }
+ else {
+ std::map<const XdmfItem * const, std::string>::const_iterator iter =
+ mImpl->mXPath.find(&array);
+ this->visit(dynamic_cast<XdmfItem &>(array), visitor);
+ if(iter == mImpl->mXPath.end()) {
+ for(unsigned int i = 0; i<xmlTextValues.size(); ++i) {
+ xmlAddChild(mImpl->mXMLCurrentNode->last,
+ xmlNewText((xmlChar*)xmlTextValues[i].c_str()));
+ }
+ }
+ }
+ mImpl->mWriteXPaths = oldWriteXPaths;
+ }
+ }
+ else {
+ // These statements are reached when an unsupported read mode is used
+ // or when a read mode is not properly set up
+ if (array.getReadMode() == XdmfArray::Reference) {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Array to be output as an array reference"
+ " does not have an associated reference.");
+ }
+ else {
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid output type.");
+ }
+ }
+
+ mImpl->mDepth--;
+ if(mImpl->mDepth <= 0) {
+ mImpl->closeFile();
+ }
+}
+
+void
+XdmfWriter::visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor)
+{
+ if (mImpl->mDepth == 0) {
+ mImpl->openFile();
+ }
+ mImpl->mDepth++;
+
+ if ((item.getItemTag().compare("Grid") != 0) || // If not a grid
+ (item.getItemTag().compare("Grid") == 0 && item.getIsChanged()) || // If a Grid that is changed
+ (item.getItemTag().compare("Grid") == 0 && !getHasXMLArchive(&item)) || // If the grid doesn't have an XML Archive
+ mRebuildAlreadyVisited) // If Rebuild
+ {
+ std::string tag = item.getItemTag();
+ if (tag.length() == 0) {
+ item.traverse(visitor);
+ }
+ else {
+ if(mImpl->mWriteXPaths) {
+ if (tag == "Information" && mImpl->mXPathParse) {
+ XdmfInformation & xpathinfo = dynamic_cast<XdmfInformation &>(item);
+ if (xpathinfo.getKey() == "XIncludes") {
+ shared_ptr<XdmfInformation> outputinfo;
+ for (unsigned int i = 0; i < xpathinfo.getNumberInformations(); ++i) {
+ mImpl->mXPathCount++;
+ outputinfo = xpathinfo.getInformation(i);
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar*)"xi:include",
+ NULL);
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)"href",
+ (xmlChar*)(outputinfo->getKey().c_str()));
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)"xpointer",
+ (xmlChar*)(outputinfo->getValue().c_str()));
+ if (i < xpathinfo.getNumberInformations()-1) {
+ mImpl->mXMLCurrentNode = mImpl->mXMLCurrentNode->parent;
+ }
+ }
+ }
+ else {
+ mImpl->mXPathCount++;
+
+ const std::string parentXPathString = mImpl->mXPathString;
+
+ std::stringstream newXPathString;
+ newXPathString << mImpl->mXPathString << "/" << mImpl->mXPathCount;
+ mImpl->mXPathString = newXPathString.str();
+
+ std::map<const XdmfItem * const, std::string>::const_iterator iter =
+ mImpl->mXPath.find(&item);
+ if(iter != mImpl->mXPath.end()) {
+ // Inserted before --- just xpath location of previously written node
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar*)"xi:include",
+ NULL);
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)"xpointer",
+ (xmlChar*)iter->second.c_str());
+ mImpl->mLastXPathed = true;
+ }
+ else {
+ // Not inserted before --- need to write all data and traverse.
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar *)tag.c_str(),
+ NULL);
+ std::stringstream xPathProp;
+ xPathProp << "element(/1" << mImpl->mXPathString << ")";
+ mImpl->mXPath.insert(std::make_pair(&item, xPathProp.str()));
+ const std::map<std::string, std::string> & itemProperties =
+ item.getItemProperties();
+ for(std::map<std::string, std::string>::const_iterator iter =
+ itemProperties.begin();
+ iter != itemProperties.end();
+ ++iter) {
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)iter->first.c_str(),
+ (xmlChar*)iter->second.c_str());
+ }
+ const unsigned int parentCount = mImpl->mXPathCount;
+ mImpl->mXPathCount = 0;
+ item.traverse(visitor);
+ mImpl->mXPathCount = parentCount;
+ mImpl->mLastXPathed = false;
+ }
+
+ mImpl->mXPathString = parentXPathString;
+
+ }
+ }
+ else {
+ mImpl->mXPathCount++;
+
+ const std::string parentXPathString = mImpl->mXPathString;
+
+ std::stringstream newXPathString;
+ newXPathString << mImpl->mXPathString << "/" << mImpl->mXPathCount;
+ mImpl->mXPathString = newXPathString.str();
+
+ std::map<const XdmfItem * const, std::string>::const_iterator iter =
+ mImpl->mXPath.find(&item);
+ if(iter != mImpl->mXPath.end()) {
+ // Inserted before --- just xpath location of previously written node
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar*)"xi:include",
+ NULL);
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)"xpointer",
+ (xmlChar*)iter->second.c_str());
+ mImpl->mLastXPathed = true;
+ }
+ else {
+ // Not inserted before --- need to write all data and traverse.
+
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar *)tag.c_str(),
+ NULL);
+ std::stringstream xPathProp;
+ xPathProp << "element(/1" << mImpl->mXPathString << ")";
+ mImpl->mXPath.insert(std::make_pair(&item, xPathProp.str()));
+ const std::map<std::string, std::string> & itemProperties =
+ item.getItemProperties();
+ for(std::map<std::string, std::string>::const_iterator iter =
+ itemProperties.begin();
+ iter != itemProperties.end();
+ ++iter) {
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)iter->first.c_str(),
+ (xmlChar*)iter->second.c_str());
+ }
+ const unsigned int parentCount = mImpl->mXPathCount;
+ mImpl->mXPathCount = 0;
+ item.traverse(visitor);
+ mImpl->mXPathCount = parentCount;
+ mImpl->mLastXPathed = false;
+ }
+ mImpl->mXPathString = parentXPathString;
+ }
+ }
+ else
+ {
+ // Increment XPathCount, handling temporary arrays not written to XPath
+ mImpl->mXPathCount++;
+ // Not inserted before --- need to write all data and traverse.
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar*)tag.c_str(),
+ NULL);
+ const std::map<std::string, std::string> itemProperties =
+ item.getItemProperties();
+ for(std::map<std::string, std::string>::const_iterator iter =
+ itemProperties.begin();
+ iter != itemProperties.end();
+ ++iter) {
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)iter->first.c_str(),
+ (xmlChar*)iter->second.c_str());
+ }
+ const unsigned int parentCount = mImpl->mXPathCount;
+ mImpl->mXPathCount = 0;
+ item.traverse(visitor);
+ mImpl->mXPathCount = parentCount;
+ mImpl->mLastXPathed = false;
+ }
+
+ if (!mRebuildAlreadyVisited)
+ {
+ if (item.getItemTag().compare("Grid") == 0)
+ {
+ setXMLNode(&item, mImpl->mXMLCurrentNode);
+ }
+ item.setIsChanged(false);
+ }
+
+ mImpl->mXMLCurrentNode = mImpl->mXMLCurrentNode->parent;
+ }
+ }
+ else
+ {
+ std::map<const XdmfItem * const, std::string>::const_iterator iter =
+ mImpl->mXPath.find(&item);
+ if(iter != mImpl->mXPath.end()) {
+ // Inserted before --- just xpath location of previously written node
+ mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode,
+ NULL,
+ (xmlChar*)"xi:include",
+ NULL);
+ xmlNewProp(mImpl->mXMLCurrentNode,
+ (xmlChar*)"xpointer",
+ (xmlChar*)iter->second.c_str());
+ mImpl->mXMLCurrentNode = mImpl->mXMLCurrentNode->parent;
+ }
+ else {
+ this->getXMLNode(&item, mImpl->mXMLDocument, mImpl->mXMLCurrentNode);
+ }
+ }
+
+ mImpl->mDepth--;
+ if(mImpl->mDepth <= 0) {
+ mImpl->mXPathCount = 0 ;
+ mImpl->closeFile();
+ }
+}
+
+// C Wrappers
+
+XDMFWRITER * XdmfWriterNew(char * fileName)
+{
+ try
+ {
+ shared_ptr<XdmfWriter> generatedWriter = XdmfWriter::New(std::string(fileName));
+ return (XDMFWRITER *)((void *)(new XdmfWriter(*generatedWriter.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfWriter> generatedWriter = XdmfWriter::New(std::string(fileName));
+ return (XDMFWRITER *)((void *)(new XdmfWriter(*generatedWriter.get())));
+ }
+}
+
+XDMFWRITER * XdmfWriterNewSpecifyHeavyDataWriter(char * fileName, XDMFHEAVYDATAWRITER * heavyDataWriter)
+{
+ try
+ {
+ shared_ptr<XdmfWriter> generatedWriter = XdmfWriter::New(std::string(fileName), shared_ptr<XdmfHeavyDataWriter>((XdmfHeavyDataWriter *) heavyDataWriter));
+ return (XDMFWRITER *)((void *)(new XdmfWriter(*generatedWriter.get())));
+ }
+ catch (...)
+ {
+ shared_ptr<XdmfWriter> generatedWriter = XdmfWriter::New(std::string(fileName), shared_ptr<XdmfHeavyDataWriter>((XdmfHeavyDataWriter *) heavyDataWriter));
+ return (XDMFWRITER *)((void *)(new XdmfWriter(*generatedWriter.get())));
+ }
+}
+
+void XdmfWriterFree(XDMFWRITER * item)
+{
+ if (item != NULL) {
+ delete ((XdmfWriter *)item);
+ item = NULL;
+ }
+}
+
+char * XdmfWriterGetFilePath(XDMFWRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ char * returnPointer = strdup(((XdmfWriter *)writer)->getFilePath().c_str());
+ return returnPointer;
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+XDMFHEAVYDATAWRITER * XdmfWriterGetHeavyDataWriter(XDMFWRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return (XDMFHEAVYDATAWRITER *)((void *)(((XdmfWriter *)writer)->getHeavyDataWriter().get()));
+ XDMF_ERROR_WRAP_END(status)
+ return NULL;
+}
+
+unsigned int XdmfWriterGetLightDataLimit(XDMFWRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return ((XdmfWriter *)writer)->getLightDataLimit();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+int XdmfWriterGetMode(XDMFWRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ XdmfWriter::Mode testMode = ((XdmfWriter *)writer)->getMode();
+ if (testMode == XdmfWriter::Default) {
+ return XDMF_WRITER_MODE_DEFAULT;
+ }
+ else if (testMode == XdmfWriter::DistributedHeavyData) {
+ return XDMF_WRITER_MODE_DISTRIBUTED_HEAVY_DATA;
+ }
+ else {
+ return -1;
+ }
+ XDMF_ERROR_WRAP_END(status)
+ return -1;
+}
+
+int XdmfWriterGetWriteXPaths(XDMFWRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return ((XdmfWriter *)writer)->getWriteXPaths();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+int XdmfWriterGetXPathParse(XDMFWRITER * writer, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ return ((XdmfWriter *)writer)->getXPathParse();
+ XDMF_ERROR_WRAP_END(status)
+ return 0;
+}
+
+void XdmfWriterSetHeavyDataWriter(XDMFWRITER * writer, XDMFHEAVYDATAWRITER * heavyDataWriter, int transferOwnership, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ if (transferOwnership) {
+ ((XdmfWriter *)writer)->setHeavyDataWriter(shared_ptr<XdmfHeavyDataWriter>((XdmfHeavyDataWriter *) heavyDataWriter));
+ }
+ else {
+ ((XdmfWriter *)writer)->setHeavyDataWriter(shared_ptr<XdmfHeavyDataWriter>((XdmfHeavyDataWriter *) heavyDataWriter, XdmfNullDeleter()));
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfWriterSetLightDataLimit(XDMFWRITER * writer, unsigned int numValues, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfWriter *)writer)->setLightDataLimit(numValues);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfWriterSetMode(XDMFWRITER * writer, int mode, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ switch (mode) {
+ case XDMF_WRITER_MODE_DEFAULT:
+ ((XdmfWriter *)writer)->setMode(XdmfWriter::Default);
+ break;
+ case XDMF_WRITER_MODE_DISTRIBUTED_HEAVY_DATA:
+ ((XdmfWriter *)writer)->setMode(XdmfWriter::DistributedHeavyData);
+ break;
+ default:
+ XdmfError::message(XdmfError::FATAL,
+ "Error: Invalid writer mode.");
+ }
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfWriterSetWriteXPaths(XDMFWRITER * writer, int writeXPaths, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfWriter *)writer)->setWriteXPaths(writeXPaths);
+ XDMF_ERROR_WRAP_END(status)
+}
+
+void XdmfWriterSetXPathParse(XDMFWRITER * writer, int xPathParse, int * status)
+{
+ XDMF_ERROR_WRAP_START(status)
+ ((XdmfWriter *)writer)->setXPathParse(xPathParse);
+ XDMF_ERROR_WRAP_END(status)
+}
--- /dev/null
+/*****************************************************************************/
+/* XDMF */
+/* eXtensible Data Model and Format */
+/* */
+/* Id : XdmfWriter.hpp */
+/* */
+/* Author: */
+/* Kenneth Leiter */
+/* kenneth.leiter@arl.army.mil */
+/* US Army Research Laboratory */
+/* Aberdeen Proving Ground, MD */
+/* */
+/* Copyright @ 2011 US Army Research Laboratory */
+/* All Rights Reserved */
+/* See Copyright.txt for details */
+/* */
+/* This software is distributed WITHOUT ANY WARRANTY; without */
+/* even the implied warranty of MERCHANTABILITY or FITNESS */
+/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
+/* for more information. */
+/* */
+/*****************************************************************************/
+
+#ifndef XDMFWRITER_HPP_
+#define XDMFWRITER_HPP_
+
+// C Compatible Includes
+#include "XdmfCore.hpp"
+#include "XdmfHeavyDataWriter.hpp"
+#include "XdmfVisitor.hpp"
+
+#ifdef __cplusplus
+
+// Forward Declarations
+class XdmfArray;
+class XdmfInformation;
+class XdmfHeavyDataWriter;
+
+/**
+ * @brief Traverse the Xdmf graph and write light and heavy data
+ * stored to disk.
+ *
+ * XdmfWriter visits each node of an Xdmf graph structure and writes
+ * data to disk. Writing begins by calling the accept() operation on
+ * any XdmfItem and supplying this writer as the parameter. The
+ * XdmfItem as well as all children attached to the XdmfItem are
+ * written to disk. Heavy data is written to a heavy data format using
+ * an XdmfHeavyDataWriter and light data is written to XML.
+ *
+ * An infinite loop is possible if an XdmfItem somehow ends up as its own child,
+ * either directly or by way of another Xdmf Item.
+ *
+ * By default, the XdmfWriter writes all heavy data to a single heavy
+ * data file specified by the XdmfHeavyDataWriter. If a dataset is
+ * encountered that resides in a different heavy data file on disk,
+ * the dataset is read from disk and written to the new heavy data
+ * file. If this is undesired, the XdmfWriter can be set to
+ * DistributedHeavyData mode in which the writer will automatically
+ * reference any heavy dataset even if it resides in a different file
+ * than the one currently being written to.
+ */
+class XDMFCORE_EXPORT XdmfWriter : public XdmfVisitor,
+ public Loki::Visitor<XdmfArray> {
+
+public:
+
+ enum Mode {
+ Default,
+ DistributedHeavyData
+ };
+
+ /**
+ * Create a new XdmfWriter to write Xdmf data to disk. This will
+ * create its own hdf5 writer based on the xmlFileName. For example,
+ * if supplied "output.xmf" the created hdf5 writer would write to
+ * file "output.h5".
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#initialization
+ * @until //#initialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//initialization
+ * @until #//initialization
+ *
+ * @param xmlFilePath The path to the xml file to write to.
+ *
+ * @return The new XdmfWriter.
+ */
+ static shared_ptr<XdmfWriter> New(const std::string & xmlFilePath);
+
+ /**
+ * Create a new XdmfWriter to write Xdmf data to disk. This will
+ * utilize the passed heavy data writer to write any heavy data to
+ * disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ *
+ * @param xmlFilePath The path to the xml file to write to.
+ * @param heavyDataWriter The heavy data writer to use when writing.
+ *
+ * @return The new XdmfWriter.
+ */
+ static shared_ptr<XdmfWriter> New(const std::string & xmlFilePath,
+ const shared_ptr<XdmfHeavyDataWriter> heavyDataWriter);
+
+ /**
+ * Create a new XdmfWriter to write Xdmf data to disk. This will
+ * write heavy data to disk using the passed heavy data writer and
+ * will add xml output to the stream.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline #//bufferinitialization
+ * @until #//bufferinitialization
+ *
+ * Python: does not curretnly support this version of New
+ *
+ * @param stream The output stream to write light data to.
+ * @param heavyDataWriter The heavy data writer to use when writing.
+ *
+ * @return The new XdmfWriter.
+ */
+ static shared_ptr<XdmfWriter> New(std::ostream & stream,
+ const shared_ptr<XdmfHeavyDataWriter> heavyDataWriter);
+
+ virtual ~XdmfWriter();
+
+ /**
+ * Get the absolute path to the XML file on disk this writer is
+ * writing to.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getFilePath
+ * @until //#getFilePath
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getFilePath
+ * @until //#getFilePath
+ *
+ * @return A std::string containing the path to the XML file on disk this
+ * writer is writing to.
+ */
+ std::string getFilePath() const;
+
+ /**
+ * Get the heavy data writer that this XdmfWriter uses to write
+ * heavy data to disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getHeavyDataWriter
+ * @until //#getHeavyDataWriter
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getHeavyDataWriter
+ * @until #//getHeavyDataWriter
+ *
+ * @return The requested heavy data writer.
+ */
+ shared_ptr<XdmfHeavyDataWriter> getHeavyDataWriter();
+
+ /**
+ * Get the heavy data writer that this XdmfWriter uses to write
+ * heavy data to disk (const version).
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getHeavyDataWriterconst
+ * @until //#getHeavyDataWriterconst
+ *
+ * Python: Does not support a contant version of this function
+ *
+ * @return The requested heavy data writer.
+ */
+ shared_ptr<const XdmfHeavyDataWriter> getHeavyDataWriter() const;
+
+ /**
+ * Get the number of values that this writer writes to light data
+ * (XML) before switching to a heavy data format.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getLightDataLimit
+ * @until //#getLightDataLimit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getLightDataLimit
+ * @until #//getLightDataLimit
+ *
+ * @return An unsigned int containing the number of values.
+ */
+ unsigned int getLightDataLimit() const;
+
+ /**
+ * Get the Mode of operation for this writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getMode
+ * @until //#getMode
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getMode
+ * @until #//getMode
+ *
+ * @return The Mode of operation for this writer.
+ */
+ Mode getMode() const;
+
+ /**
+ * Gets whether XML is rebuilt with each write.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getRebuildXML
+ * @until //#getRebuildXML
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getRebuildXML
+ * @until #//getRebuildXML
+ *
+ * @return Whether XML will be rebuilt.
+ */
+ bool getRebuildXML();
+
+ /**
+ * Get whether this writer is set to write xpaths.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getWriteXPaths
+ * @until //#getWriteXPaths
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getWriteXPaths
+ * @until #//getWriteXPaths
+ *
+ * @return bool whether this writer is set to write xpaths.
+ */
+ bool getWriteXPaths() const;
+
+ /**
+ * Get whether this writer is set to parse xpaths from information.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getXPathParse
+ * @until //#getXPathParse
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getXPathParse
+ * @until #//getXPathParse
+ *
+ * @return bool whether this writer is set to write xpaths.
+ */
+ bool getXPathParse() const;
+
+ /**
+ * Set the heavy data writer that this XdmfWriter uses to write
+ * heavy data to disk.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#getHeavyDataWriter
+ * @until //#getHeavyDataWriter
+ * @skipline //#setHeavyDataWriter
+ * @until //#setHeavyDataWriter
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//getHeavyDataWriter
+ * @until #//getHeavyDataWriter
+ * @skipline #//setHeavyDataWriter
+ * @until #//setHeavyDataWriter
+ *
+ * @param heavyDataWriter The heavy data writer to set.
+ */
+ void setHeavyDataWriter(shared_ptr<XdmfHeavyDataWriter> heavyDataWriter);
+
+ /**
+ * Set the number of values that this writer writes to light data
+ * (XML) before switching to a heavy data format.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#setLightDataLimit
+ * @until //#setLightDataLimit
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//setLightDataLimit
+ * @until #//setLightDataLimit
+ *
+ * @param numValues An unsigned int containing the number of values.
+ */
+ void setLightDataLimit(const unsigned int numValues);
+
+ /**
+ * Set the mode of operation for this writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#setMode
+ * @until //#setMode
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//setMode
+ * @until #//setMode
+ *
+ * @param mode The Mode of operation for this writer.
+ */
+ void setMode(const Mode mode);
+
+ /**
+ * Sets whether XML will be rebuilt with each write.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#setRebuildXML
+ * @until //#setRebuildXML
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//setRebuildXML
+ * @until #//setRebuildXML
+ *
+ * @param newStatus Whether to rebuild XML.
+ */
+ void setRebuildXML(bool newStatus);
+
+ /**
+ * Set whether to write xpaths for this writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#setWriteXPaths
+ * @until //#setWriteXPaths
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//setWriteXPaths
+ * @until #//setWriteXPaths
+ *
+ * @param writeXPaths Whether to write xpaths for this writer.
+ */
+ void setWriteXPaths(const bool writeXPaths = true);
+
+ /**
+ * Set whether to parse xpaths from infomation for this writer.
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#heavyinitialization
+ * @until //#heavyinitialization
+ * @skipline //#setXPathParse
+ * @until //#setXPathParse
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//heavyinitialization
+ * @until #//heavyinitialization
+ * @skipline #//setXPathParse
+ * @until #//setXPathParse
+ *
+ * @param xPathParse Whether to write xpaths for this writer.
+ */
+ void setXPathParse(const bool xPathParse = true);
+
+ /**
+ * Write an XdmfArray to disk
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#visitarray
+ * @until //#visitarray
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//visitarray
+ * @until #//visitarray
+ *
+ * @param array An XdmfArray to write to disk.
+ * @param visitor A smart pointer to this visitor --- aids in grid traversal.
+ */
+ virtual void visit(XdmfArray & array,
+ const shared_ptr<XdmfBaseVisitor> visitor);
+
+ /**
+ * Write an XdmfItem to disk
+ *
+ * Example of use:
+ *
+ * C++
+ *
+ * @dontinclude ExampleXdmfWriter.cpp
+ * @skipline //#visititem
+ * @until //#visititem
+ *
+ * Python
+ *
+ * @dontinclude XdmfExampleWriter.py
+ * @skipline #//visititem
+ * @until #//visititem
+ *
+ * @param item An XdmfItem to write to disk.
+ * @param visitor A smart pointer to this visitor --- aids in grid traversal.
+ */
+ virtual void visit(XdmfItem & item,
+ const shared_ptr<XdmfBaseVisitor> visitor);
+
+ XdmfWriter(const XdmfWriter &);
+
+protected:
+
+ XdmfWriter(const std::string & xmlFilePath,
+ shared_ptr<XdmfHeavyDataWriter> heavyDataWriter,
+ std::ostream * stream = NULL);
+
+ xmlNodePtr getXMLNode(XdmfItem * item, xmlDocPtr parentDoc, xmlNodePtr parentNode);
+ bool getHasXMLArchive(XdmfItem * item);
+ void setXMLNode(XdmfItem * item, xmlNodePtr & newNode);
+
+ void setDocumentTitle(std::string title);
+ void setVersionString(std::string version);
+
+ bool mRebuildAlreadyVisited;
+
+ std::map<XdmfItem *, xmlNodePtr> mXMLArchive;
+
+private:
+
+ /**
+ * PIMPL
+ */
+ class XdmfWriterImpl;
+
+ void operator=(const XdmfWriter &); // Not implemented.
+
+ XdmfWriterImpl * mImpl;
+
+};
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define XDMF_WRITER_MODE_DEFAULT 30
+#define XDMF_WRITER_MODE_DISTRIBUTED_HEAVY_DATA 31
+
+// C wrappers go here
+
+struct XDMFWRITER; // Simply as a typedef to ensure correct typing
+typedef struct XDMFWRITER XDMFWRITER;
+
+XDMFCORE_EXPORT XDMFWRITER * XdmfWriterNew(char * fileName);
+
+XDMFCORE_EXPORT XDMFWRITER * XdmfWriterNewSpecifyHeavyDataWriter(char * fileName, XDMFHEAVYDATAWRITER * heavyDataWriter);
+
+XDMFCORE_EXPORT void XdmfWriterFree(XDMFWRITER * item);
+
+XDMFCORE_EXPORT char * XdmfWriterGetFilePath(XDMFWRITER * writer, int * status);
+
+XDMFCORE_EXPORT XDMFHEAVYDATAWRITER * XdmfWriterGetHeavyDataWriter(XDMFWRITER * writer, int * status);
+
+XDMFCORE_EXPORT unsigned int XdmfWriterGetLightDataLimit(XDMFWRITER * writer, int * status);
+
+XDMFCORE_EXPORT int XdmfWriterGetMode(XDMFWRITER * writer, int * status);
+
+XDMFCORE_EXPORT int XdmfWriterGetWriteXPaths(XDMFWRITER * writer, int * status);
+
+XDMFCORE_EXPORT int XdmfWriterGetXPathParse(XDMFWRITER * writer, int * status);
+
+XDMFCORE_EXPORT void XdmfWriterSetHeavyDataWriter(XDMFWRITER * writer, XDMFHEAVYDATAWRITER * heavyDataWriter, int transferOwnership, int * status);
+
+XDMFCORE_EXPORT void XdmfWriterSetLightDataLimit(XDMFWRITER * writer, unsigned int numValues, int * status);
+
+XDMFCORE_EXPORT void XdmfWriterSetMode(XDMFWRITER * writer, int mode, int * status);
+
+XDMFCORE_EXPORT void XdmfWriterSetWriteXPaths(XDMFWRITER * writer, int writeXPaths, int * status);
+
+XDMFCORE_EXPORT void XdmfWriterSetXPathParse(XDMFWRITER * writer, int xPathParse, int * status);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* XDMFWRITER_HPP_ */
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Wesley Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_EMPTYTYPE_INC_
+#define LOKI_EMPTYTYPE_INC_
+
+// $Id: EmptyType.h 751 2006-10-17 19:50:37Z syntheticpp $
+
+
+namespace Loki
+{
+////////////////////////////////////////////////////////////////////////////////
+// class EmptyType
+// Used as a class type that doesn't hold anything
+// Useful as a strawman class
+////////////////////////////////////////////////////////////////////////////////
+
+ class EmptyType {};
+
+
+ inline bool operator==(const EmptyType&, const EmptyType&)
+ {
+ return true;
+ }
+
+ inline bool operator<(const EmptyType&, const EmptyType&)
+ {
+ return false;
+ }
+
+ inline bool operator>(const EmptyType&, const EmptyType&)
+ {
+ return false;
+ }
+}
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Wesley Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_HIERARCHYGENERATORS_INC_
+#define LOKI_HIERARCHYGENERATORS_INC_
+
+// $Id: HierarchyGenerators.h 751 2006-10-17 19:50:37Z syntheticpp $
+
+
+#include "Typelist.h"
+#include "TypeTraits.h"
+#include "EmptyType.h"
+
+namespace Loki
+{
+#if defined(_MSC_VER) && _MSC_VER >= 1300
+#pragma warning( push )
+ // 'class1' : base-class 'class2' is already a base-class of 'class3'
+#pragma warning( disable : 4584 )
+#endif // _MSC_VER
+
+////////////////////////////////////////////////////////////////////////////////
+// class template GenScatterHierarchy
+// Generates a scattered hierarchy starting from a typelist and a template
+// Invocation (TList is a typelist, Unit is a template of one arg):
+// GenScatterHierarchy<TList, Unit>
+// The generated class inherits all classes generated by instantiating the
+// template 'Unit' with the types contained in TList
+////////////////////////////////////////////////////////////////////////////////
+
+ namespace Private
+ {
+ // The following type helps to overcome subtle flaw in the original
+ // implementation of GenScatterHierarchy.
+ // The flaw is revealed when the input type list of GenScatterHierarchy
+ // contains more then one element of the same type (e.g. LOKI_TYPELIST_2(int, int)).
+ // In this case GenScatterHierarchy will contain multiple bases of the same
+ // type and some of them will not be reachable (per 10.3).
+ // For example before the fix the first element of Tuple<LOKI_TYPELIST_2(int, int)>
+ // is not reachable in any way!
+ template<class, class>
+ struct ScatterHierarchyTag;
+ }
+
+ template <class TList, template <class> class Unit>
+ class GenScatterHierarchy;
+
+ template <class T1, class T2, template <class> class Unit>
+ class GenScatterHierarchy<Typelist<T1, T2>, Unit>
+ : public GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit>
+ , public GenScatterHierarchy<T2, Unit>
+ {
+ public:
+ typedef Typelist<T1, T2> TList;
+ // Insure that LeftBase is unique and therefore reachable
+ typedef GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit> LeftBase;
+ typedef GenScatterHierarchy<T2, Unit> RightBase;
+ template <typename T> struct Rebind
+ {
+ typedef Unit<T> Result;
+ };
+ };
+
+ // In the middle *unique* class that resolve possible ambiguity
+ template <class T1, class T2, template <class> class Unit>
+ class GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit>
+ : public GenScatterHierarchy<T1, Unit>
+ {
+ };
+
+ template <class AtomicType, template <class> class Unit>
+ class GenScatterHierarchy : public Unit<AtomicType>
+ {
+ typedef Unit<AtomicType> LeftBase;
+ template <typename T> struct Rebind
+ {
+ typedef Unit<T> Result;
+ };
+ };
+
+ template <template <class> class Unit>
+ class GenScatterHierarchy<NullType, Unit>
+ {
+ template <typename T> struct Rebind
+ {
+ typedef Unit<T> Result;
+ };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// function template Field
+// Accesses a field in an object of a type generated with GenScatterHierarchy
+// Invocation (obj is an object of a type H generated with GenScatterHierarchy,
+// T is a type in the typelist used to generate H):
+// Field<T>(obj)
+// returns a reference to Unit<T>, where Unit is the template used to generate H
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class T, class H>
+ typename H::template Rebind<T>::Result& Field(H& obj)
+ {
+ return obj;
+ }
+
+ template <class T, class H>
+ const typename H::template Rebind<T>::Result& Field(const H& obj)
+ {
+ return obj;
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+// function template TupleUnit
+// The building block of tuples
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class T>
+ struct TupleUnit
+ {
+ T value_;
+ operator T&() { return value_; }
+ operator const T&() const { return value_; }
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Tuple
+// Implements a tuple class that holds a number of values and provides field
+// access to them via the Field function (below)
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList>
+ struct Tuple : public GenScatterHierarchy<TList, TupleUnit>
+ {
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// helper class template FieldHelper
+// See Field below
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class H, unsigned int i> struct FieldHelper;
+
+ template <class H>
+ struct FieldHelper<H, 0>
+ {
+ typedef typename H::TList::Head ElementType;
+ typedef typename H::template Rebind<ElementType>::Result UnitType;
+
+ enum
+ {
+ isTuple = Conversion<UnitType, TupleUnit<ElementType> >::sameType,
+ isConst = TypeTraits<H>::isConst
+ };
+
+ typedef const typename H::LeftBase ConstLeftBase;
+
+ typedef typename Select<isConst, ConstLeftBase,
+ typename H::LeftBase>::Result LeftBase;
+
+ typedef typename Select<isTuple, ElementType,
+ UnitType>::Result UnqualifiedResultType;
+
+ typedef typename Select<isConst, const UnqualifiedResultType,
+ UnqualifiedResultType>::Result ResultType;
+
+ static ResultType& Do(H& obj)
+ {
+ LeftBase& leftBase = obj;
+ return leftBase;
+ }
+ };
+
+ template <class H, unsigned int i>
+ struct FieldHelper
+ {
+ typedef typename TL::TypeAt<typename H::TList, i>::Result ElementType;
+ typedef typename H::template Rebind<ElementType>::Result UnitType;
+
+ enum
+ {
+ isTuple = Conversion<UnitType, TupleUnit<ElementType> >::sameType,
+ isConst = TypeTraits<H>::isConst
+ };
+
+ typedef const typename H::RightBase ConstRightBase;
+
+ typedef typename Select<isConst, ConstRightBase,
+ typename H::RightBase>::Result RightBase;
+
+ typedef typename Select<isTuple, ElementType,
+ UnitType>::Result UnqualifiedResultType;
+
+ typedef typename Select<isConst, const UnqualifiedResultType,
+ UnqualifiedResultType>::Result ResultType;
+
+ static ResultType& Do(H& obj)
+ {
+ RightBase& rightBase = obj;
+ return FieldHelper<RightBase, i - 1>::Do(rightBase);
+ }
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// function template Field
+// Accesses a field in an object of a type generated with GenScatterHierarchy
+// Invocation (obj is an object of a type H generated with GenScatterHierarchy,
+// i is the index of a type in the typelist used to generate H):
+// Field<i>(obj)
+// returns a reference to Unit<T>, where Unit is the template used to generate H
+// and T is the i-th type in the typelist
+////////////////////////////////////////////////////////////////////////////////
+
+ template <int i, class H>
+ typename FieldHelper<H, i>::ResultType&
+ Field(H& obj)
+ {
+ return FieldHelper<H, i>::Do(obj);
+ }
+
+// template <int i, class H>
+// const typename FieldHelper<H, i>::ResultType&
+// Field(const H& obj)
+// {
+// return FieldHelper<H, i>::Do(obj);
+// }
+
+////////////////////////////////////////////////////////////////////////////////
+// class template GenLinearHierarchy
+// Generates a linear hierarchy starting from a typelist and a template
+// Invocation (TList is a typelist, Unit is a template of two args):
+// GenScatterHierarchy<TList, Unit>
+////////////////////////////////////////////////////////////////////////////////
+
+ template
+ <
+ class TList,
+ template <class AtomicType, class Base> class Unit,
+ class Root = EmptyType
+ >
+ class GenLinearHierarchy;
+
+ template
+ <
+ class T1,
+ class T2,
+ template <class, class> class Unit,
+ class Root
+ >
+ class GenLinearHierarchy<Typelist<T1, T2>, Unit, Root>
+ : public Unit< T1, GenLinearHierarchy<T2, Unit, Root> >
+ {
+ };
+
+ template
+ <
+ class T,
+ template <class, class> class Unit,
+ class Root
+ >
+ class GenLinearHierarchy<Typelist<T, NullType>, Unit, Root>
+ : public Unit<T, Root>
+ {
+ };
+
+ template
+ <
+ template <class, class> class Unit,
+ class Root
+ >
+ class GenLinearHierarchy<NullType , Unit, Root>
+ : public Root // is this better: Unit<NullType, Root> ?
+ {
+ };
+
+#if defined(_MSC_VER) && _MSC_VER >= 1300
+#pragma warning( pop )
+#endif
+} // namespace Loki
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Wesley Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_NULLTYPE_INC_
+#define LOKI_NULLTYPE_INC_
+
+// $Id: NullType.h 751 2006-10-17 19:50:37Z syntheticpp $
+
+
+namespace Loki
+{
+////////////////////////////////////////////////////////////////////////////////
+// class NullType
+// Used as a placeholder for "no type here"
+// Useful as an end marker in typelists
+////////////////////////////////////////////////////////////////////////////////
+
+ class NullType {};
+
+} // namespace Loki
+
+
+#endif // end file guardian
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2005 by Peter Kümmel
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author makes no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_SEQUENCE_INC_
+#define LOKI_SEQUENCE_INC_
+
+// $Id: Sequence.h 768 2006-10-25 20:40:40Z syntheticpp $
+
+
+#include "Typelist.h"
+
+namespace Loki
+{
+
+ template
+ <
+ class T01=NullType,class T02=NullType,class T03=NullType,class T04=NullType,class T05=NullType,
+ class T06=NullType,class T07=NullType,class T08=NullType,class T09=NullType,class T10=NullType,
+ class T11=NullType,class T12=NullType,class T13=NullType,class T14=NullType,class T15=NullType,
+ class T16=NullType,class T17=NullType,class T18=NullType,class T19=NullType,class T20=NullType
+ >
+ struct Seq
+ {
+ private:
+ typedef typename Seq< T02, T03, T04, T05, T06, T07, T08, T09, T10,
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>::Type
+ TailResult;
+ public:
+ typedef Typelist<T01, TailResult> Type;
+ };
+
+ template<>
+ struct Seq<>
+ {
+ typedef NullType Type;
+ };
+
+} // namespace Loki
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Welsey Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_TYPEMANIP_INC_
+#define LOKI_TYPEMANIP_INC_
+
+// $Id: TypeManip.h 749 2006-10-17 19:49:26Z syntheticpp $
+
+
+namespace Loki
+{
+////////////////////////////////////////////////////////////////////////////////
+// class template Int2Type
+// Converts each integral constant into a unique type
+// Invocation: Int2Type<v> where v is a compile-time constant integral
+// Defines 'value', an enum that evaluates to v
+////////////////////////////////////////////////////////////////////////////////
+
+ template <int v>
+ struct Int2Type
+ {
+ enum { value = v };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Type2Type
+// Converts each type into a unique, insipid type
+// Invocation Type2Type<T> where T is a type
+// Defines the type OriginalType which maps back to T
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename T>
+ struct Type2Type
+ {
+ typedef T OriginalType;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Select
+// Selects one of two types based upon a boolean constant
+// Invocation: Select<flag, T, U>::Result
+// where:
+// flag is a compile-time boolean constant
+// T and U are types
+// Result evaluates to T if flag is true, and to U otherwise.
+////////////////////////////////////////////////////////////////////////////////
+
+ template <bool flag, typename T, typename U>
+ struct Select
+ {
+ typedef T Result;
+ };
+ template <typename T, typename U>
+ struct Select<false, T, U>
+ {
+ typedef U Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template IsSameType
+// Return true iff two given types are the same
+// Invocation: SameType<T, U>::value
+// where:
+// T and U are types
+// Result evaluates to true iff U == T (types equal)
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename T, typename U>
+ struct IsSameType
+ {
+ enum { value = false };
+ };
+
+ template <typename T>
+ struct IsSameType<T,T>
+ {
+ enum { value = true };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big)
+////////////////////////////////////////////////////////////////////////////////
+
+ namespace Private
+ {
+ template <class T, class U>
+ struct ConversionHelper
+ {
+ typedef char Small;
+ struct Big { char dummy[2]; };
+ static Big Test(...);
+ static Small Test(U);
+ static T MakeT();
+ };
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Conversion
+// Figures out the conversion relationships between two types
+// Invocations (T and U are types):
+// a) Conversion<T, U>::exists
+// returns (at compile time) true if there is an implicit conversion from T
+// to U (example: Derived to Base)
+// b) Conversion<T, U>::exists2Way
+// returns (at compile time) true if there are both conversions from T
+// to U and from U to T (example: int to char and back)
+// c) Conversion<T, U>::sameType
+// returns (at compile time) true if T and U represent the same type
+//
+// Caveat: might not work if T and U are in a private inheritance hierarchy.
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class T, class U>
+ struct Conversion
+ {
+ typedef Private::ConversionHelper<T, U> H;
+#ifndef __MWERKS__
+ enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };
+#else
+ enum { exists = false };
+#endif
+ enum { exists2Way = exists && Conversion<U, T>::exists };
+ enum { sameType = false };
+ };
+
+ template <class T>
+ struct Conversion<T, T>
+ {
+ enum { exists = 1, exists2Way = 1, sameType = 1 };
+ };
+
+ template <class T>
+ struct Conversion<void, T>
+ {
+ enum { exists = 0, exists2Way = 0, sameType = 0 };
+ };
+
+ template <class T>
+ struct Conversion<T, void>
+ {
+ enum { exists = 0, exists2Way = 0, sameType = 0 };
+ };
+
+ template <>
+ struct Conversion<void, void>
+ {
+ public:
+ enum { exists = 1, exists2Way = 1, sameType = 1 };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template SuperSubclass
+// Invocation: SuperSubclass<B, D>::value where B and D are types.
+// Returns true if B is a public base of D, or if B and D are aliases of the
+// same type.
+//
+// Caveat: might not work if T and U are in a private inheritance hierarchy.
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T, class U>
+struct SuperSubclass
+{
+ enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
+ !::Loki::Conversion<const volatile T*, const volatile void*>::sameType) };
+
+ // Dummy enum to make sure that both classes are fully defined.
+ enum{ dontUseWithIncompleteTypes = ( sizeof (T) == sizeof (U) ) };
+};
+
+template <>
+struct SuperSubclass<void, void>
+{
+ enum { value = false };
+};
+
+template <class U>
+struct SuperSubclass<void, U>
+{
+ enum { value = (::Loki::Conversion<const volatile U*, const volatile void*>::exists &&
+ !::Loki::Conversion<const volatile void*, const volatile void*>::sameType) };
+
+ // Dummy enum to make sure that both classes are fully defined.
+ enum{ dontUseWithIncompleteTypes = ( 0 == sizeof (U) ) };
+};
+
+template <class T>
+struct SuperSubclass<T, void>
+{
+ enum { value = (::Loki::Conversion<const volatile void*, const volatile T*>::exists &&
+ !::Loki::Conversion<const volatile T*, const volatile void*>::sameType) };
+
+ // Dummy enum to make sure that both classes are fully defined.
+ enum{ dontUseWithIncompleteTypes = ( sizeof (T) == 0 ) };
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// class template SuperSubclassStrict
+// Invocation: SuperSubclassStrict<B, D>::value where B and D are types.
+// Returns true if B is a public base of D.
+//
+// Caveat: might not work if T and U are in a private inheritance hierarchy.
+////////////////////////////////////////////////////////////////////////////////
+
+template<class T,class U>
+struct SuperSubclassStrict
+{
+ enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
+ !::Loki::Conversion<const volatile T*, const volatile void*>::sameType &&
+ !::Loki::Conversion<const volatile T*, const volatile U*>::sameType) };
+
+ // Dummy enum to make sure that both classes are fully defined.
+ enum{ dontUseWithIncompleteTypes = ( sizeof (T) == sizeof (U) ) };
+};
+
+template<>
+struct SuperSubclassStrict<void, void>
+{
+ enum { value = false };
+};
+
+template<class U>
+struct SuperSubclassStrict<void, U>
+{
+ enum { value = (::Loki::Conversion<const volatile U*, const volatile void*>::exists &&
+ !::Loki::Conversion<const volatile void*, const volatile void*>::sameType &&
+ !::Loki::Conversion<const volatile void*, const volatile U*>::sameType) };
+
+ // Dummy enum to make sure that both classes are fully defined.
+ enum{ dontUseWithIncompleteTypes = ( 0 == sizeof (U) ) };
+};
+
+template<class T>
+struct SuperSubclassStrict<T, void>
+{
+ enum { value = (::Loki::Conversion<const volatile void*, const volatile T*>::exists &&
+ !::Loki::Conversion<const volatile T*, const volatile void*>::sameType &&
+ !::Loki::Conversion<const volatile T*, const volatile void*>::sameType) };
+
+ // Dummy enum to make sure that both classes are fully defined.
+ enum{ dontUseWithIncompleteTypes = ( sizeof (T) == 0 ) };
+};
+
+
+} // namespace Loki
+
+////////////////////////////////////////////////////////////////////////////////
+// macro SUPERSUBCLASS
+// Invocation: SUPERSUBCLASS(B, D) where B and D are types.
+// Returns true if B is a public base of D, or if B and D are aliases of the
+// same type.
+//
+// Caveat: might not work if T and U are in a private inheritance hierarchy.
+// Deprecated: Use SuperSubclass class template instead.
+////////////////////////////////////////////////////////////////////////////////
+
+#define LOKI_SUPERSUBCLASS(T, U) \
+ ::Loki::SuperSubclass<T,U>::value
+
+////////////////////////////////////////////////////////////////////////////////
+// macro SUPERSUBCLASS_STRICT
+// Invocation: SUPERSUBCLASS(B, D) where B and D are types.
+// Returns true if B is a public base of D.
+//
+// Caveat: might not work if T and U are in a private inheritance hierarchy.
+// Deprecated: Use SuperSubclassStrict class template instead.
+////////////////////////////////////////////////////////////////////////////////
+
+#define LOKI_SUPERSUBCLASS_STRICT(T, U) \
+ ::Loki::SuperSubclassStrict<T,U>::value
+
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Wesley Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_TYPETRAITS_INC_
+#define LOKI_TYPETRAITS_INC_
+
+// $Id: TypeTraits.h 835 2007-08-02 19:39:02Z syntheticpp $
+
+
+#include "Typelist.h"
+#include "Sequence.h"
+
+#if (defined _MSC_VER) && (_MSC_VER < 1400)
+#include <string>
+#endif
+
+
+#ifdef _MSC_VER
+#pragma warning( push )
+#pragma warning( disable : 4180 ) //qualifier applied to function type has no meaning; ignored
+#endif
+
+namespace Loki
+{
+////////////////////////////////////////////////////////////////////////////////
+// class template IsCustomUnsignedInt
+// Offers a means to integrate nonstandard built-in unsigned integral types
+// (such as unsigned __int64 or unsigned long long int) with the TypeTraits
+// class template defined below.
+// Invocation: IsCustomUnsignedInt<T> where T is any type
+// Defines 'value', an enum that is 1 iff T is a custom built-in unsigned
+// integral type
+// Specialize this class template for nonstandard unsigned integral types
+// and define value = 1 in those specializations
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename T>
+ struct IsCustomUnsignedInt
+ {
+ enum { value = 0 };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template IsCustomSignedInt
+// Offers a means to integrate nonstandard built-in unsigned integral types
+// (such as unsigned __int64 or unsigned long long int) with the TypeTraits
+// class template defined below.
+// Invocation: IsCustomSignedInt<T> where T is any type
+// Defines 'value', an enum that is 1 iff T is a custom built-in signed
+// integral type
+// Specialize this class template for nonstandard unsigned integral types
+// and define value = 1 in those specializations
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename T>
+ struct IsCustomSignedInt
+ {
+ enum { value = 0 };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template IsCustomFloat
+// Offers a means to integrate nonstandard floating point types with the
+// TypeTraits class template defined below.
+// Invocation: IsCustomFloat<T> where T is any type
+// Defines 'value', an enum that is 1 iff T is a custom built-in
+// floating point type
+// Specialize this class template for nonstandard unsigned integral types
+// and define value = 1 in those specializations
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename T>
+ struct IsCustomFloat
+ {
+ enum { value = 0 };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// Helper types for class template TypeTraits defined below
+////////////////////////////////////////////////////////////////////////////////
+
+ namespace Private
+ {
+#ifndef LOKI_DISABLE_TYPELIST_MACROS
+ typedef LOKI_TYPELIST_4(unsigned char, unsigned short int,unsigned int, unsigned long int)
+ StdUnsignedInts;
+ typedef LOKI_TYPELIST_4(signed char, short int,int, long int)
+ StdSignedInts;
+ typedef LOKI_TYPELIST_3(bool, char, wchar_t)
+ StdOtherInts;
+ typedef LOKI_TYPELIST_3(float, double, long double)
+ StdFloats;
+#else
+ typedef Loki::Seq<unsigned char, unsigned short int,unsigned int, unsigned long int>::Type
+ StdUnsignedInts;
+ typedef Loki::Seq<signed char, short int,int, long int>::Type
+ StdSignedInts;
+ typedef Loki::Seq<bool, char, wchar_t>::Type
+ StdOtherInts;
+ typedef Loki::Seq<float, double, long double>::Type
+ StdFloats;
+
+#endif
+ template <typename U> struct AddPointer
+ {
+ typedef U* Result;
+ };
+
+ template <typename U> struct AddPointer<U&>
+ {
+ typedef U* Result;
+ };
+
+ template <class U> struct AddReference
+ {
+ typedef U & Result;
+ };
+
+ template <class U> struct AddReference<U &>
+ {
+ typedef U & Result;
+ };
+
+ template <> struct AddReference<void>
+ {
+ typedef NullType Result;
+ };
+
+ template <class U> struct AddParameterType
+ {
+ typedef const U & Result;
+ };
+
+ template <class U> struct AddParameterType<U &>
+ {
+ typedef U & Result;
+ };
+
+ template <> struct AddParameterType<void>
+ {
+ typedef NullType Result;
+ };
+
+ template <typename T>
+ struct IsFunctionPointerRaw
+ {enum{result = 0};};
+
+ template <typename T>
+ struct IsFunctionPointerRaw<T(*)()>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01>
+ struct IsFunctionPointerRaw<T(*)(P01)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20)>
+ {enum {result = 1};};
+
+ template <typename T>
+ struct IsFunctionPointerRaw<T(*)(
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, ...)>
+ {enum {result = 1};};
+
+ template <typename T,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsFunctionPointerRaw<T(*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20,
+ ...)>
+ {enum {result = 1};};
+
+
+ template <typename T>
+ struct IsMemberFunctionPointerRaw
+ {enum{result = 0};};
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)()>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(P01)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20)>
+ {enum {result = 1};};
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, ...)>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20,
+ ...)>
+ {enum {result = 1};};
+
+ // Const versions
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)() const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(P01) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, ...) const>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20,
+ ...) const>
+ {enum {result = 1};};
+
+ // Volatile versions
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)() volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(P01) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, ...) volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20,
+ ...) volatile>
+ {enum {result = 1};};
+
+ // Const volatile versions
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)() const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(P01) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, ...) const volatile>
+ {enum {result = 1};};
+
+ template <typename T, typename S,
+ typename P01, typename P02, typename P03, typename P04, typename P05,
+ typename P06, typename P07, typename P08, typename P09, typename P10,
+ typename P11, typename P12, typename P13, typename P14, typename P15,
+ typename P16, typename P17, typename P18, typename P19, typename P20>
+ struct IsMemberFunctionPointerRaw<T (S::*)(
+ P01, P02, P03, P04, P05,
+ P06, P07, P08, P09, P10,
+ P11, P12, P13, P14, P15,
+ P16, P17, P18, P19, P20,
+ ...) const volatile>
+ {enum {result = 1};};
+
+ }// namespace Private
+
+////////////////////////////////////////////////////////////////////////////////
+// class template TypeTraits
+//
+// Figures out at compile time various properties of any given type
+// Invocations (T is a type, TypeTraits<T>::Property):
+//
+// - isPointer : returns true if T is a pointer type
+// - PointeeType : returns the type to which T points if T is a pointer
+// type, NullType otherwise
+// - isReference : returns true if T is a reference type
+// - ReferredType : returns the type to which T refers if T is a reference
+// type, NullType otherwise
+// - isMemberPointer : returns true if T is a pointer to member type
+// - isStdUnsignedInt: returns true if T is a standard unsigned integral type
+// - isStdSignedInt : returns true if T is a standard signed integral type
+// - isStdIntegral : returns true if T is a standard integral type
+// - isStdFloat : returns true if T is a standard floating-point type
+// - isStdArith : returns true if T is a standard arithmetic type
+// - isStdFundamental: returns true if T is a standard fundamental type
+// - isUnsignedInt : returns true if T is a unsigned integral type
+// - isSignedInt : returns true if T is a signed integral type
+// - isIntegral : returns true if T is a integral type
+// - isFloat : returns true if T is a floating-point type
+// - isArith : returns true if T is a arithmetic type
+// - isFundamental : returns true if T is a fundamental type
+// - ParameterType : returns the optimal type to be used as a parameter for
+// functions that take Ts
+// - isConst : returns true if T is a const-qualified type
+// - NonConstType : Type with removed 'const' qualifier from T, if any
+// - isVolatile : returns true if T is a volatile-qualified type
+// - NonVolatileType : Type with removed 'volatile' qualifier from T, if any
+// - UnqualifiedType : Type with removed 'const' and 'volatile' qualifiers from
+// T, if any
+// - ParameterType : returns the optimal type to be used as a parameter
+// for functions that take 'const T's
+//
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename T>
+ class TypeTraits
+ {
+ private:
+
+ template <class U> struct ReferenceTraits
+ {
+ enum { result = false };
+ typedef U ReferredType;
+ };
+
+ template <class U> struct ReferenceTraits<U&>
+ {
+ enum { result = true };
+ typedef U ReferredType;
+ };
+
+ template <class U> struct PointerTraits
+ {
+ enum { result = false };
+ typedef NullType PointeeType;
+ };
+
+ template <class U> struct PointerTraits<U*>
+ {
+ enum { result = true };
+ typedef U PointeeType;
+ };
+
+ template <class U> struct PointerTraits<U*&>
+ {
+ enum { result = true };
+ typedef U PointeeType;
+ };
+
+ template <class U> struct PToMTraits
+ {
+ enum { result = false };
+ };
+
+ template <class U, class V> struct PToMTraits<U V::*>
+ {
+ enum { result = true };
+ };
+
+ template <class U, class V> struct PToMTraits<U V::*&>
+ {
+ enum { result = true };
+ };
+
+ template <class U> struct FunctionPointerTraits
+ {
+ enum{ result = Private::IsFunctionPointerRaw<U>::result };
+ };
+
+ template <typename U> struct PToMFunctionTraits
+ {
+ enum{ result = Private::IsMemberFunctionPointerRaw<U>::result };
+ };
+
+ template <class U> struct UnConst
+ {
+ typedef U Result;
+ enum { isConst = 0 };
+ };
+
+ template <class U> struct UnConst<const U>
+ {
+ typedef U Result;
+ enum { isConst = 1 };
+ };
+
+ template <class U> struct UnConst<const U&>
+ {
+ typedef U& Result;
+ enum { isConst = 1 };
+ };
+
+ template <class U> struct UnVolatile
+ {
+ typedef U Result;
+ enum { isVolatile = 0 };
+ };
+
+ template <class U> struct UnVolatile<volatile U>
+ {
+ typedef U Result;
+ enum { isVolatile = 1 };
+ };
+
+ template <class U> struct UnVolatile<volatile U&>
+ {
+ typedef U& Result;
+ enum { isVolatile = 1 };
+ };
+
+ public:
+ typedef typename UnConst<T>::Result
+ NonConstType;
+ typedef typename UnVolatile<T>::Result
+ NonVolatileType;
+ typedef typename UnVolatile<typename UnConst<T>::Result>::Result
+ UnqualifiedType;
+ typedef typename PointerTraits<UnqualifiedType>::PointeeType
+ PointeeType;
+ typedef typename ReferenceTraits<T>::ReferredType
+ ReferredType;
+
+ enum { isConst = UnConst<T>::isConst };
+ enum { isVolatile = UnVolatile<T>::isVolatile };
+ enum { isReference = ReferenceTraits<UnqualifiedType>::result };
+ enum { isFunction = FunctionPointerTraits<typename Private::AddPointer<T>::Result >::result };
+ enum { isFunctionPointer= FunctionPointerTraits<
+ typename ReferenceTraits<UnqualifiedType>::ReferredType >::result };
+ enum { isMemberFunctionPointer= PToMFunctionTraits<
+ typename ReferenceTraits<UnqualifiedType>::ReferredType >::result };
+ enum { isMemberPointer = PToMTraits<
+ typename ReferenceTraits<UnqualifiedType>::ReferredType >::result ||
+ isMemberFunctionPointer };
+ enum { isPointer = PointerTraits<
+ typename ReferenceTraits<UnqualifiedType>::ReferredType >::result ||
+ isFunctionPointer };
+
+ enum { isStdUnsignedInt = TL::IndexOf<Private::StdUnsignedInts, UnqualifiedType>::value >= 0 ||
+ TL::IndexOf<Private::StdUnsignedInts,
+ typename ReferenceTraits<UnqualifiedType>::ReferredType>::value >= 0};
+ enum { isStdSignedInt = TL::IndexOf<Private::StdSignedInts, UnqualifiedType>::value >= 0 ||
+ TL::IndexOf<Private::StdSignedInts,
+ typename ReferenceTraits<UnqualifiedType>::ReferredType>::value >= 0};
+ enum { isStdIntegral = isStdUnsignedInt || isStdSignedInt ||
+ TL::IndexOf<Private::StdOtherInts, UnqualifiedType>::value >= 0 ||
+ TL::IndexOf<Private::StdOtherInts,
+ typename ReferenceTraits<UnqualifiedType>::ReferredType>::value >= 0};
+ enum { isStdFloat = TL::IndexOf<Private::StdFloats, UnqualifiedType>::value >= 0 ||
+ TL::IndexOf<Private::StdFloats,
+ typename ReferenceTraits<UnqualifiedType>::ReferredType>::value >= 0};
+ enum { isStdArith = isStdIntegral || isStdFloat };
+ enum { isStdFundamental = isStdArith || isStdFloat || Conversion<T, void>::sameType };
+
+ enum { isUnsignedInt = isStdUnsignedInt || IsCustomUnsignedInt<UnqualifiedType>::value };
+ enum { isSignedInt = isStdSignedInt || IsCustomSignedInt<UnqualifiedType>::value };
+ enum { isIntegral = isStdIntegral || isUnsignedInt || isSignedInt };
+ enum { isFloat = isStdFloat || IsCustomFloat<UnqualifiedType>::value };
+ enum { isArith = isIntegral || isFloat };
+ enum { isFundamental = isStdFundamental || isArith };
+
+ typedef typename Select<isStdArith || isPointer || isMemberPointer, T,
+ typename Private::AddParameterType<T>::Result>::Result
+ ParameterType;
+ };
+}
+
+#ifdef _MSC_VER
+#pragma warning( pop )
+#endif // _MSC_VER
+
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Welsey Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_TYPELIST_INC_
+#define LOKI_TYPELIST_INC_
+
+// $Id: Typelist.h 749 2006-10-17 19:49:26Z syntheticpp $
+
+
+#include "NullType.h"
+#include "TypeManip.h"
+#include "TypelistMacros.h"
+
+
+namespace Loki
+{
+////////////////////////////////////////////////////////////////////////////////
+// class template Typelist
+// The building block of typelists of any length
+// Use it through the LOKI_TYPELIST_NN macros
+// Defines nested types:
+// Head (first element, a non-typelist type by convention)
+// Tail (second element, can be another typelist)
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class T, class U>
+ struct Typelist
+ {
+ typedef T Head;
+ typedef U Tail;
+ };
+
+// Typelist utility algorithms
+
+ namespace TL
+ {
+
+////////////////////////////////////////////////////////////////////////////////
+// class template MakeTypelist
+// Takes a number of arguments equal to its numeric suffix
+// The arguments are type names.
+// MakeTypelist<T1, T2, ...>::Result
+// returns a typelist that is of T1, T2, ...
+////////////////////////////////////////////////////////////////////////////////
+
+ template
+ <
+ typename T1 = NullType, typename T2 = NullType, typename T3 = NullType,
+ typename T4 = NullType, typename T5 = NullType, typename T6 = NullType,
+ typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
+ typename T10 = NullType, typename T11 = NullType, typename T12 = NullType,
+ typename T13 = NullType, typename T14 = NullType, typename T15 = NullType,
+ typename T16 = NullType, typename T17 = NullType, typename T18 = NullType
+ >
+ struct MakeTypelist
+ {
+ private:
+ typedef typename MakeTypelist
+ <
+ T2 , T3 , T4 ,
+ T5 , T6 , T7 ,
+ T8 , T9 , T10,
+ T11, T12, T13,
+ T14, T15, T16,
+ T17, T18
+ >
+ ::Result TailResult;
+
+ public:
+ typedef Typelist<T1, TailResult> Result;
+ };
+
+ template<>
+ struct MakeTypelist<>
+ {
+ typedef NullType Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Length
+// Computes the length of a typelist
+// Invocation (TList is a typelist):
+// Length<TList>::value
+// returns a compile-time constant containing the length of TList, not counting
+// the end terminator (which by convention is NullType)
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList> struct Length;
+ template <> struct Length<NullType>
+ {
+ enum { value = 0 };
+ };
+
+ template <class T, class U>
+ struct Length< Typelist<T, U> >
+ {
+ enum { value = 1 + Length<U>::value };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template TypeAt
+// Finds the type at a given index in a typelist
+// Invocation (TList is a typelist and index is a compile-time integral
+// constant):
+// TypeAt<TList, index>::Result
+// returns the type in position 'index' in TList
+// If you pass an out-of-bounds index, the result is a compile-time error
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, unsigned int index> struct TypeAt;
+
+ template <class Head, class Tail>
+ struct TypeAt<Typelist<Head, Tail>, 0>
+ {
+ typedef Head Result;
+ };
+
+ template <class Head, class Tail, unsigned int i>
+ struct TypeAt<Typelist<Head, Tail>, i>
+ {
+ typedef typename TypeAt<Tail, i - 1>::Result Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template TypeAtNonStrict
+// Finds the type at a given index in a typelist
+// Invocations (TList is a typelist and index is a compile-time integral
+// constant):
+// a) TypeAt<TList, index>::Result
+// returns the type in position 'index' in TList, or NullType if index is
+// out-of-bounds
+// b) TypeAt<TList, index, D>::Result
+// returns the type in position 'index' in TList, or D if index is out-of-bounds
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, unsigned int index,
+ typename DefaultType = NullType>
+ struct TypeAtNonStrict
+ {
+ typedef DefaultType Result;
+ };
+
+ template <class Head, class Tail, typename DefaultType>
+ struct TypeAtNonStrict<Typelist<Head, Tail>, 0, DefaultType>
+ {
+ typedef Head Result;
+ };
+
+ template <class Head, class Tail, unsigned int i, typename DefaultType>
+ struct TypeAtNonStrict<Typelist<Head, Tail>, i, DefaultType>
+ {
+ typedef typename
+ TypeAtNonStrict<Tail, i - 1, DefaultType>::Result Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template IndexOf
+// Finds the index of a type in a typelist
+// Invocation (TList is a typelist and T is a type):
+// IndexOf<TList, T>::value
+// returns the position of T in TList, or NullType if T is not found in TList
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T> struct IndexOf;
+
+ template <class T>
+ struct IndexOf<NullType, T>
+ {
+ enum { value = -1 };
+ };
+
+ template <class T, class Tail>
+ struct IndexOf<Typelist<T, Tail>, T>
+ {
+ enum { value = 0 };
+ };
+
+ template <class Head, class Tail, class T>
+ struct IndexOf<Typelist<Head, Tail>, T>
+ {
+ private:
+ enum { temp = IndexOf<Tail, T>::value };
+ public:
+ enum { value = (temp == -1 ? -1 : 1 + temp) };
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Append
+// Appends a type or a typelist to another
+// Invocation (TList is a typelist and T is either a type or a typelist):
+// Append<TList, T>::Result
+// returns a typelist that is TList followed by T and NullType-terminated
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T> struct Append;
+
+ template <> struct Append<NullType, NullType>
+ {
+ typedef NullType Result;
+ };
+
+ template <class T> struct Append<NullType, T>
+ {
+ typedef Typelist<T,NullType> Result;
+ };
+
+ template <class Head, class Tail>
+ struct Append<NullType, Typelist<Head, Tail> >
+ {
+ typedef Typelist<Head, Tail> Result;
+ };
+
+ template <class Head, class Tail, class T>
+ struct Append<Typelist<Head, Tail>, T>
+ {
+ typedef Typelist<Head,
+ typename Append<Tail, T>::Result>
+ Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Erase
+// Erases the first occurence, if any, of a type in a typelist
+// Invocation (TList is a typelist and T is a type):
+// Erase<TList, T>::Result
+// returns a typelist that is TList without the first occurence of T
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T> struct Erase;
+
+ template <class T> // Specialization 1
+ struct Erase<NullType, T>
+ {
+ typedef NullType Result;
+ };
+
+ template <class T, class Tail> // Specialization 2
+ struct Erase<Typelist<T, Tail>, T>
+ {
+ typedef Tail Result;
+ };
+
+ template <class Head, class Tail, class T> // Specialization 3
+ struct Erase<Typelist<Head, Tail>, T>
+ {
+ typedef Typelist<Head,
+ typename Erase<Tail, T>::Result>
+ Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template EraseAll
+// Erases all first occurences, if any, of a type in a typelist
+// Invocation (TList is a typelist and T is a type):
+// EraseAll<TList, T>::Result
+// returns a typelist that is TList without any occurence of T
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T> struct EraseAll;
+ template <class T>
+ struct EraseAll<NullType, T>
+ {
+ typedef NullType Result;
+ };
+ template <class T, class Tail>
+ struct EraseAll<Typelist<T, Tail>, T>
+ {
+ // Go all the way down the list removing the type
+ typedef typename EraseAll<Tail, T>::Result Result;
+ };
+ template <class Head, class Tail, class T>
+ struct EraseAll<Typelist<Head, Tail>, T>
+ {
+ // Go all the way down the list removing the type
+ typedef Typelist<Head,
+ typename EraseAll<Tail, T>::Result>
+ Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template NoDuplicates
+// Removes all duplicate types in a typelist
+// Invocation (TList is a typelist):
+// NoDuplicates<TList, T>::Result
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList> struct NoDuplicates;
+
+ template <> struct NoDuplicates<NullType>
+ {
+ typedef NullType Result;
+ };
+
+ template <class Head, class Tail>
+ struct NoDuplicates< Typelist<Head, Tail> >
+ {
+ private:
+ typedef typename NoDuplicates<Tail>::Result L1;
+ typedef typename Erase<L1, Head>::Result L2;
+ public:
+ typedef Typelist<Head, L2> Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Replace
+// Replaces the first occurence of a type in a typelist, with another type
+// Invocation (TList is a typelist, T, U are types):
+// Replace<TList, T, U>::Result
+// returns a typelist in which the first occurence of T is replaced with U
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T, class U> struct Replace;
+
+ template <class T, class U>
+ struct Replace<NullType, T, U>
+ {
+ typedef NullType Result;
+ };
+
+ template <class T, class Tail, class U>
+ struct Replace<Typelist<T, Tail>, T, U>
+ {
+ typedef Typelist<U, Tail> Result;
+ };
+
+ template <class Head, class Tail, class T, class U>
+ struct Replace<Typelist<Head, Tail>, T, U>
+ {
+ typedef Typelist<Head,
+ typename Replace<Tail, T, U>::Result>
+ Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template ReplaceAll
+// Replaces all occurences of a type in a typelist, with another type
+// Invocation (TList is a typelist, T, U are types):
+// Replace<TList, T, U>::Result
+// returns a typelist in which all occurences of T is replaced with U
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T, class U> struct ReplaceAll;
+
+ template <class T, class U>
+ struct ReplaceAll<NullType, T, U>
+ {
+ typedef NullType Result;
+ };
+
+ template <class T, class Tail, class U>
+ struct ReplaceAll<Typelist<T, Tail>, T, U>
+ {
+ typedef Typelist<U, typename ReplaceAll<Tail, T, U>::Result> Result;
+ };
+
+ template <class Head, class Tail, class T, class U>
+ struct ReplaceAll<Typelist<Head, Tail>, T, U>
+ {
+ typedef Typelist<Head,
+ typename ReplaceAll<Tail, T, U>::Result>
+ Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Reverse
+// Reverses a typelist
+// Invocation (TList is a typelist):
+// Reverse<TList>::Result
+// returns a typelist that is TList reversed
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList> struct Reverse;
+
+ template <>
+ struct Reverse<NullType>
+ {
+ typedef NullType Result;
+ };
+
+ template <class Head, class Tail>
+ struct Reverse< Typelist<Head, Tail> >
+ {
+ typedef typename Append<
+ typename Reverse<Tail>::Result, Head>::Result Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template MostDerived
+// Finds the type in a typelist that is the most derived from a given type
+// Invocation (TList is a typelist, T is a type):
+// MostDerived<TList, T>::Result
+// returns the type in TList that's the most derived from T
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList, class T> struct MostDerived;
+
+ template <class T>
+ struct MostDerived<NullType, T>
+ {
+ typedef T Result;
+ };
+
+ template <class Head, class Tail, class T>
+ struct MostDerived<Typelist<Head, Tail>, T>
+ {
+ private:
+ typedef typename MostDerived<Tail, T>::Result Candidate;
+ public:
+ typedef typename Select<
+ SuperSubclass<Candidate,Head>::value,
+ Head, Candidate>::Result Result;
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+// class template DerivedToFront
+// Arranges the types in a typelist so that the most derived types appear first
+// Invocation (TList is a typelist):
+// DerivedToFront<TList>::Result
+// returns the reordered TList
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class TList> struct DerivedToFront;
+
+ template <>
+ struct DerivedToFront<NullType>
+ {
+ typedef NullType Result;
+ };
+
+ template <class Head, class Tail>
+ struct DerivedToFront< Typelist<Head, Tail> >
+ {
+ private:
+ typedef typename MostDerived<Tail, Head>::Result
+ TheMostDerived;
+ typedef typename Replace<Tail,
+ TheMostDerived, Head>::Result Temp;
+ typedef typename DerivedToFront<Temp>::Result L;
+ public:
+ typedef Typelist<TheMostDerived, L> Result;
+ };
+
+ } // namespace TL
+} // namespace Loki
+
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Welsey Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef LOKI_TYPELISTMACROS_INC_
+#define LOKI_TYPELISTMACROS_INC_
+
+// $Id: TypelistMacros.h 749 2006-10-17 19:49:26Z syntheticpp $
+
+
+//#define LOKI_DISABLE_TYPELIST_MACROS
+#ifndef LOKI_DISABLE_TYPELIST_MACROS
+
+////////////////////////////////////////////////////////////////////////////////
+// macros LOKI_TYPELIST_1, LOKI_TYPELIST_2, ... LOKI_TYPELIST_50
+// Each takes a number of arguments equal to its numeric suffix
+// The arguments are type names. LOKI_TYPELIST_NN generates a typelist containing
+// all types passed as arguments, in that order.
+// Example: LOKI_TYPELIST_2(char, int) generates a type containing char and int.
+////////////////////////////////////////////////////////////////////////////////
+
+#define LOKI_TYPELIST_1(T1) ::Loki::Typelist<T1, ::Loki::NullType>
+
+#define LOKI_TYPELIST_2(T1, T2) ::Loki::Typelist<T1, LOKI_TYPELIST_1(T2) >
+
+#define LOKI_TYPELIST_3(T1, T2, T3) ::Loki::Typelist<T1, LOKI_TYPELIST_2(T2, T3) >
+
+#define LOKI_TYPELIST_4(T1, T2, T3, T4) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_3(T2, T3, T4) >
+
+#define LOKI_TYPELIST_5(T1, T2, T3, T4, T5) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_4(T2, T3, T4, T5) >
+
+#define LOKI_TYPELIST_6(T1, T2, T3, T4, T5, T6) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_5(T2, T3, T4, T5, T6) >
+
+#define LOKI_TYPELIST_7(T1, T2, T3, T4, T5, T6, T7) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_6(T2, T3, T4, T5, T6, T7) >
+
+#define LOKI_TYPELIST_8(T1, T2, T3, T4, T5, T6, T7, T8) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_7(T2, T3, T4, T5, T6, T7, T8) >
+
+#define LOKI_TYPELIST_9(T1, T2, T3, T4, T5, T6, T7, T8, T9) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_8(T2, T3, T4, T5, T6, T7, T8, T9) >
+
+#define LOKI_TYPELIST_10(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_9(T2, T3, T4, T5, T6, T7, T8, T9, T10) >
+
+#define LOKI_TYPELIST_11(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_10(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) >
+
+#define LOKI_TYPELIST_12(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_11(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12) >
+
+#define LOKI_TYPELIST_13(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_12(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13) >
+
+#define LOKI_TYPELIST_14(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_13(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14) >
+
+#define LOKI_TYPELIST_15(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_14(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15) >
+
+#define LOKI_TYPELIST_16(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_15(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16) >
+
+#define LOKI_TYPELIST_17(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_16(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17) >
+
+#define LOKI_TYPELIST_18(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_17(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18) >
+
+#define LOKI_TYPELIST_19(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_18(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19) >
+
+#define LOKI_TYPELIST_20(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_19(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) >
+
+#define LOKI_TYPELIST_21(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_20(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) >
+
+#define LOKI_TYPELIST_22(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_21(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) >
+
+#define LOKI_TYPELIST_23(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_22(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) >
+
+#define LOKI_TYPELIST_24(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_23(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24) >
+
+#define LOKI_TYPELIST_25(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_24(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25) >
+
+#define LOKI_TYPELIST_26(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_25(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26) >
+
+#define LOKI_TYPELIST_27(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_26(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27) >
+
+#define LOKI_TYPELIST_28(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_27(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28) >
+
+#define LOKI_TYPELIST_29(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_28(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29) >
+
+#define LOKI_TYPELIST_30(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_29(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) >
+
+#define LOKI_TYPELIST_31(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_30(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) >
+
+#define LOKI_TYPELIST_32(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_31(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) >
+
+#define LOKI_TYPELIST_33(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_32(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) >
+
+#define LOKI_TYPELIST_34(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_33(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) >
+
+#define LOKI_TYPELIST_35(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_34(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35) >
+
+#define LOKI_TYPELIST_36(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_35(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36) >
+
+#define LOKI_TYPELIST_37(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_36(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37) >
+
+#define LOKI_TYPELIST_38(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_37(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38) >
+
+#define LOKI_TYPELIST_39(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_38(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39) >
+
+#define LOKI_TYPELIST_40(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_39(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40) >
+
+#define LOKI_TYPELIST_41(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_40(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) >
+
+#define LOKI_TYPELIST_42(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_41(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) >
+
+#define LOKI_TYPELIST_43(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_42(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) >
+
+#define LOKI_TYPELIST_44(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_43(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44) >
+
+#define LOKI_TYPELIST_45(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_44(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45) >
+
+#define LOKI_TYPELIST_46(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_45(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46) >
+
+#define LOKI_TYPELIST_47(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_46(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47) >
+
+#define LOKI_TYPELIST_48(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47, T48) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_47(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47, T48) >
+
+#define LOKI_TYPELIST_49(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47, T48, T49) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_48(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47, T48, T49) >
+
+#define LOKI_TYPELIST_50(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) \
+ ::Loki::Typelist<T1, LOKI_TYPELIST_49(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
+ T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
+ T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) >
+
+#endif //LOKI_DISABLE_TYPELIST_MACROS
+
+#endif // end file guardian
+
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (c) 2001 by Andrei Alexandrescu
+// This code accompanies the book:
+// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
+// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
+// Permission to use, copy, modify, distribute and sell this software for any
+// purpose is hereby granted without fee, provided that the above copyright
+// notice appear in all copies and that both that copyright notice and this
+// permission notice appear in supporting documentation.
+// The author or Addison-Wesley Longman make no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+
+// $Header: /cvsroot-fuse/loki-lib/loki/include/loki/Visitor.h,v 1.7 2006/01/16 19:05:09 rich_sposato Exp $
+
+/// \defgroup VisitorGroup Visitor
+
+#ifndef LOKI_VISITOR_INC_
+#define LOKI_VISITOR_INC_
+
+#include "Typelist.h"
+#include "HierarchyGenerators.h"
+#include "XdmfSharedPtr.hpp"
+
+namespace Loki
+{
+
+////////////////////////////////////////////////////////////////////////////////
+/// \class BaseVisitor
+///
+/// \ingroup VisitorGroup
+/// The base class of any Acyclic Visitor
+////////////////////////////////////////////////////////////////////////////////
+
+ class BaseVisitor
+ {
+ public:
+ virtual ~BaseVisitor() {}
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+/// \class Visitor
+///
+/// \ingroup VisitorGroup
+/// The building block of Acyclic Visitor
+///
+/// \par Usage
+///
+/// Defining the visitable class:
+///
+/// \code
+/// class RasterBitmap : public BaseVisitable<>
+/// {
+/// public:
+/// LOKI_DEFINE_VISITABLE()
+/// };
+/// \endcode
+///
+/// Way 1 to define a visitor:
+/// \code
+/// class SomeVisitor :
+/// public BaseVisitor // required
+/// public Visitor<RasterBitmap>,
+/// public Visitor<Paragraph>
+/// {
+/// public:
+/// void Visit(RasterBitmap&); // visit a RasterBitmap
+/// void Visit(Paragraph &); // visit a Paragraph
+/// };
+/// \endcode
+///
+/// Way 2 to define the visitor:
+/// \code
+/// class SomeVisitor :
+/// public BaseVisitor // required
+/// public Visitor<LOKI_TYPELIST_2(RasterBitmap, Paragraph)>
+/// {
+/// public:
+/// void Visit(RasterBitmap&); // visit a RasterBitmap
+/// void Visit(Paragraph &); // visit a Paragraph
+/// };
+/// \endcode
+///
+/// Way 3 to define the visitor:
+/// \code
+/// class SomeVisitor :
+/// public BaseVisitor // required
+/// public Visitor<Seq<RasterBitmap, Paragraph>::Type>
+/// {
+/// public:
+/// void Visit(RasterBitmap&); // visit a RasterBitmap
+/// void Visit(Paragraph &); // visit a Paragraph
+/// };
+/// \endcode
+///
+/// \par Using const visit functions:
+///
+/// Defining the visitable class (true for const):
+///
+/// \code
+/// class RasterBitmap : public BaseVisitable<void, DefaultCatchAll, true>
+/// {
+/// public:
+/// LOKI_DEFINE_CONST_VISITABLE()
+/// };
+/// \endcode
+///
+/// Defining the visitor which only calls const member functions:
+/// \code
+/// class SomeVisitor :
+/// public BaseVisitor // required
+/// public Visitor<RasterBitmap, void, true>,
+/// {
+/// public:
+/// void Visit(const RasterBitmap&); // visit a RasterBitmap by a const member function
+/// };
+/// \endcode
+///
+/// \par Example:
+///
+/// test/Visitor/main.cpp
+////////////////////////////////////////////////////////////////////////////////
+
+ template <class T, typename R = void, bool ConstVisit = false>
+ class Visitor;
+
+ template <class T, typename R>
+ class Visitor<T, R, false>
+ {
+ public:
+ typedef R ReturnType;
+ typedef T ParamType;
+ virtual ~Visitor() {}
+ virtual ReturnType visit(ParamType&, shared_ptr<BaseVisitor>) = 0;
+ };
+
+ /*
+ template <class T, typename R>
+ class Visitor<T, R, true>
+ {
+ public:
+ typedef R ReturnType;
+ typedef const T ParamType;
+ virtual ~Visitor() {}
+ virtual ReturnType visit(ParamType&, shared_ptr<BaseVisitor>) = 0;
+ };
+ */
+
+////////////////////////////////////////////////////////////////////////////////
+// class template Visitor (specialization)
+// This specialization is not present in the book. It makes it easier to define
+// Visitors for multiple types in a shot by using a typelist. Example:
+//
+// class SomeVisitor :
+// public BaseVisitor // required
+// public Visitor<LOKI_TYPELIST_2(RasterBitmap, Paragraph)>
+// {
+// public:
+// void Visit(RasterBitmap&); // visit a RasterBitmap
+// void Visit(Paragraph &); // visit a Paragraph
+// };
+////////////////////////////////////////////////////////////////////////////////
+
+/* template <class Head, class Tail, typename R> */
+/* class Visitor<Typelist<Head, Tail>, R, false> */
+/* : public Visitor<Head, R, false>, public Visitor<Tail, R, false> */
+/* { */
+/* public: */
+/* typedef R ReturnType; */
+/* // using Visitor<Head, R>::Visit; */
+/* // using Visitor<Tail, R>::Visit; */
+/* }; */
+
+/* template <class Head, typename R> */
+/* class Visitor<Typelist<Head, NullType>, R, false> : public Visitor<Head, R, false> */
+/* { */
+/* public: */
+/* typedef R ReturnType; */
+/* using Visitor<Head, R, false>::Visit; */
+/* }; */
+
+/* template <class Head, class Tail, typename R> */
+/* class Visitor<Typelist<Head, Tail>, R, true> */
+/* : public Visitor<Head, R, true>, public Visitor<Tail, R, true> */
+/* { */
+/* public: */
+/* typedef R ReturnType; */
+/* // using Visitor<Head, R>::Visit; */
+/* // using Visitor<Tail, R>::Visit; */
+/* }; */
+
+/* template <class Head, typename R> */
+/* class Visitor<Typelist<Head, NullType>, R, true> : public Visitor<Head, R, true> */
+/* { */
+/* public: */
+/* typedef R ReturnType; */
+/* using Visitor<Head, R, true>::visit; */
+/* }; */
+
+
+////////////////////////////////////////////////////////////////////////////////
+// class template BaseVisitorImpl
+// Implements non-strict visitation (you can implement only part of the Visit
+// functions)
+////////////////////////////////////////////////////////////////////////////////
+/*
+ template <class TList, typename R = void> class BaseVisitorImpl;
+
+ template <class Head, class Tail, typename R>
+ class BaseVisitorImpl<Typelist<Head, Tail>, R>
+ : public Visitor<Head, R>
+ , public BaseVisitorImpl<Tail, R>
+ {
+ public:
+ // using BaseVisitorImpl<Tail, R>::Visit;
+
+ virtual R visit(Head&, shared_ptr<BaseVisitor>)
+ { return R(); }
+ };
+
+ template <class Head, typename R>
+ class BaseVisitorImpl<Typelist<Head, NullType>, R>
+ : public Visitor<Head, R>
+ {
+ public:
+ virtual R visit(Head&, shared_ptr<BaseVisitor>)
+ { return R(); }
+ };
+*/
+////////////////////////////////////////////////////////////////////////////////
+// class template BaseVisitable
+////////////////////////////////////////////////////////////////////////////////
+/*
+template <typename R, typename Visited>
+struct DefaultCatchAll
+{
+ static R OnUnknownVisitor(Visited&, BaseVisitor&)
+ { return R(); }
+};
+*/
+////////////////////////////////////////////////////////////////////////////////
+// class template BaseVisitable
+////////////////////////////////////////////////////////////////////////////////
+
+ template
+ <
+ typename R = void,
+ bool ConstVisitable = false
+ >
+ class BaseVisitable;
+
+ template<typename R>
+ class BaseVisitable<R, false>
+ {
+ public:
+ typedef R ReturnType;
+ virtual ~BaseVisitable() {}
+ virtual ReturnType accept(const shared_ptr<BaseVisitor>&) = 0;
+
+ protected: // give access only to the hierarchy
+
+ template <class T>
+ static ReturnType acceptImpl(T& visited, const shared_ptr<BaseVisitor>& guest)
+ {
+ // Apply the Acyclic Visitor
+ if (Visitor<T,R>* p = dynamic_cast<Visitor<T,R>*>(guest.get()))
+ {
+ p->visit(visited, guest);
+ }
+ return;
+ }
+ };
+
+ template<typename R>
+ class BaseVisitable<R, true>
+ {
+ public:
+ typedef R ReturnType;
+ virtual ~BaseVisitable() {}
+ virtual ReturnType accept(BaseVisitor&) const = 0;
+
+ protected: // give access only to the hierarchy
+ template <class T>
+ static ReturnType acceptImpl(const T& visited, const shared_ptr<BaseVisitor>& guest)
+ {
+ // Apply the Acyclic Visitor
+ if (Visitor<T,R,true>* p = dynamic_cast<Visitor<T,R,true>*>(guest.get()))
+ {
+ p->visit(visited, guest);
+ }
+ return;
+ }
+ };
+
+
+ template< >
+ class BaseVisitable<void, false>
+ {
+ typedef void R;
+ public:
+ typedef R ReturnType;
+ virtual ~BaseVisitable() {}
+ virtual ReturnType accept(const shared_ptr<BaseVisitor>&) = 0;
+
+ protected: // give access only to the hierarchy
+
+ template <class T>
+ static ReturnType acceptImpl(T& visited, const shared_ptr<BaseVisitor>& guest)
+ {
+ // Apply the Acyclic Visitor
+ if (Visitor<T,R>* p = dynamic_cast<Visitor<T,R>*>(guest.get()))
+ {
+ p->visit(visited, guest);
+ }
+ }
+ };
+
+ template<>
+ class BaseVisitable<void, true>
+ {
+ typedef void R;
+ public:
+ typedef R ReturnType;
+ virtual ~BaseVisitable() {}
+ virtual ReturnType accept(BaseVisitor&) const = 0;
+
+ protected: // give access only to the hierarchy
+ template <class T>
+ static ReturnType acceptImpl(const T& visited, const shared_ptr<BaseVisitor>& guest)
+ {
+ // Apply the Acyclic Visitor
+ if (Visitor<T,R,true>* p = dynamic_cast<Visitor<T,R,true>*>(guest.get()))
+ {
+ p->visit(visited, guest);
+ }
+ }
+ };
+
+////////////////////////////////////////////////////////////////////////////////
+/// \def LOKI_DEFINE_VISITABLE()
+/// \ingroup VisitorGroup
+/// Put it in every class that you want to make visitable
+/// (in addition to deriving it from BaseVisitable<R>)
+////////////////////////////////////////////////////////////////////////////////
+
+#define LOKI_DEFINE_VISITABLE_BASE() \
+ virtual void accept(const shared_ptr<Loki::BaseVisitor> &guest) \
+ { acceptImpl(*this, guest); }
+
+#define LOKI_DEFINE_VISITABLE(my_class, my_base) \
+ virtual void accept(const shared_ptr<Loki::BaseVisitor> &guest) \
+ { \
+ Loki::BaseVisitor* t = guest.get();\
+ if (Loki::Visitor<my_class,ReturnType>* p = dynamic_cast<Loki::Visitor<my_class,ReturnType>*>(t)) \
+ { \
+ p->visit(*this, guest); \
+ } \
+ else \
+ { \
+ my_base::accept(guest); \
+ } \
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+/// \def LOKI_DEFINE_CONST_VISITABLE()
+/// \ingroup VisitorGroup
+/// Put it in every class that you want to make visitable by const member
+/// functions (in addition to deriving it from BaseVisitable<R>)
+////////////////////////////////////////////////////////////////////////////////
+/*
+#define LOKI_DEFINE_CONST_VISITABLE() \
+ virtual ReturnType accept(const shared_ptr< ::Loki::BaseVisitor> guest) const \
+ { return acceptImpl(*this, guest); }
+
+////////////////////////////////////////////////////////////////////////////////
+/// \class CyclicVisitor
+///
+/// \ingroup VisitorGroup
+/// Put it in every class that you want to make visitable (in addition to
+/// deriving it from BaseVisitable<R>
+////////////////////////////////////////////////////////////////////////////////
+
+ template <typename R, class TList>
+ class CyclicVisitor : public Visitor<TList, R>
+ {
+ public:
+ typedef R ReturnType;
+ // using Visitor<TList, R>::Visit;
+
+ template <class Visited>
+ ReturnType GenericVisit(Visited& host)
+ {
+ Visitor<Visited, ReturnType>& subObj = *this;
+ return subObj.visit(host);
+ }
+ };
+*/
+////////////////////////////////////////////////////////////////////////////////
+/// \def LOKI_DEFINE_CYCLIC_VISITABLE(SomeVisitor)
+/// \ingroup VisitorGroup
+/// Put it in every class that you want to make visitable by a cyclic visitor
+////////////////////////////////////////////////////////////////////////////////
+/*
+#define LOKI_DEFINE_CYCLIC_VISITABLE(SomeVisitor) \
+ virtual SomeVisitor::ReturnType accept(SomeVisitor& guest) \
+ { return guest.GenericVisit(*this); }
+*/
+} // namespace Loki
+
+typedef Loki::BaseVisitor XdmfBaseVisitor;
+
+////////////////////////////////////////////////////////////////////////////////
+// Change log:
+// March 20, ????: add default argument DefaultCatchAll to BaseVisitable
+// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
+// September 28, 2004: replaced Loki:: with ::Loki:: in DEFINE_VISITABLE
+// January 2, 2006: add support for visiting constant member functions, Peter K�mmel
+////////////////////////////////////////////////////////////////////////////////
+
+#endif // VISITOR_INC_
+
+// $Log: Visitor.h,v $
+// Revision 1.7 2006/01/16 19:05:09 rich_sposato
+// Added cvs keywords.
+//